Xenova HF Staff commited on
Commit
967779e
·
verified ·
1 Parent(s): 3bcbf19

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -0
README.md CHANGED
@@ -4,5 +4,35 @@ base_model: jmtzt/ijepa_vitg16_22k
4
  ---
5
 
6
  https://huggingface.co/jmtzt/ijepa_vitg16_22k with ONNX weights to be compatible with Transformers.js.
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
 
4
  ---
5
 
6
  https://huggingface.co/jmtzt/ijepa_vitg16_22k with ONNX weights to be compatible with Transformers.js.
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:** Image feature extraction with `onnx-community/ijepa_vitg16_22k`.
15
+
16
+ ```js
17
+ import { pipeline, cos_sim } from "@huggingface/transformers";
18
+
19
+ // Create an image feature extraction pipeline
20
+ const extractor = await pipeline(
21
+ "image-feature-extraction",
22
+ "onnx-community/ijepa_vitg16_22k",
23
+ { dtype: "q8" },
24
+ );
25
+
26
+ // Compute image embeddings
27
+ const url_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
28
+ const url_2 = "http://images.cocodataset.org/val2017/000000219578.jpg"
29
+ const output = await extractor([url_1, url_2]);
30
+ const pooled_output = output.mean(1); // Apply mean pooling
31
+
32
+ // Compute cosine similarity
33
+ const similarity = cos_sim(pooled_output[0].data, pooled_output[1].data);
34
+ console.log(similarity); // 0.4707813467804588
35
+ ```
36
+
37
+ ---
38
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).