Xenova HF staff commited on
Commit
8f1af3a
·
verified ·
1 Parent(s): e849ab8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -3
README.md CHANGED
@@ -1,3 +1,66 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ https://huggingface.co/IDEA-Research/grounding-dino-tiny with ONNX weights to be compatible with Transformers.js.
6
+
7
+ ## Usage (Transformers.js)
8
+
9
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
10
+ ```bash
11
+ npm i @huggingface/transformers
12
+ ```
13
+
14
+ **Example:** Zero-shot object detection with `onnx-community/grounding-dino-tiny-ONNX`.
15
+ ```js
16
+ import { AutoModelForZeroShotObjectDetection, AutoProcessor, load_image } from "../src/transformers.js";
17
+ // import { AutoModelForZeroShotObjectDetection, AutoProcessor, load_image } from "@huggingface/transformers";
18
+
19
+ // Load model and processor
20
+ const model_id = "onnx-community/grounding-dino-tiny-ONNX";
21
+ const processor = await AutoProcessor.from_pretrained(model_id);
22
+ const model = await AutoModelForZeroShotObjectDetection.from_pretrained(model_id, { dtype: "fp32" });
23
+
24
+ // Prepare image and text inputs
25
+ const image = await load_image("http://images.cocodataset.org/val2017/000000039769.jpg");
26
+ const text = "a cat."; // NB: text query needs to be lowercased + end with a dot
27
+
28
+ // Preprocess image and text
29
+ const inputs = await processor(image, text);
30
+
31
+ // Run model
32
+ const outputs = await model(inputs);
33
+
34
+ // Post-process outputs
35
+ const results = processor.post_process_grounded_object_detection(
36
+ outputs,
37
+ inputs.input_ids,
38
+ {
39
+ box_threshold: 0.3,
40
+ text_threshold: 0.3,
41
+ target_sizes: [image.size.reverse()],
42
+ },
43
+ );
44
+ console.log(results);
45
+ ```
46
+
47
+ <details>
48
+
49
+ <summary>See example output</summary>
50
+
51
+ ```
52
+ [
53
+ {
54
+ scores: [ 0.45316222310066223, 0.36190420389175415 ],
55
+ boxes: [
56
+ [ 343.7238121032715, 23.02229404449463, 637.0737648010254, 372.6510000228882 ],
57
+ [ 12.311229705810547, 52.27128982543945, 317.4389839172363, 472.60459899902344 ]
58
+ ],
59
+ labels: [ 'a cat', 'a cat' ]
60
+ }
61
+ ]
62
+ ```
63
+
64
+ </details>
65
+
66
+ ---