Update README.md
Browse files
README.md
CHANGED
@@ -31,27 +31,34 @@ I-JEPA can be used for image classification or feature extraction. This checkpoi
|
|
31 |
|
32 |
## How to use
|
33 |
|
34 |
-
Here is how to use this model
|
35 |
|
36 |
```python
|
37 |
import requests
|
38 |
-
|
39 |
from PIL import Image
|
40 |
-
from
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
model_id = "jmtzt/ijepa_vith16_1k"
|
46 |
processor = AutoProcessor.from_pretrained(model_id)
|
47 |
-
model =
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
```
|
56 |
|
57 |
### BibTeX entry and citation info
|
|
|
31 |
|
32 |
## How to use
|
33 |
|
34 |
+
Here is how to use this model for image feature extraction:
|
35 |
|
36 |
```python
|
37 |
import requests
|
|
|
38 |
from PIL import Image
|
39 |
+
from torch.nn.functional import cosine_similarity
|
40 |
+
|
41 |
+
from transformers import AutoModel, AutoProcessor
|
42 |
|
43 |
+
url_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
44 |
+
url_2 = "http://images.cocodataset.org/val2017/000000219578.jpg"
|
45 |
+
image_1 = Image.open(requests.get(url_1, stream=True).raw)
|
46 |
+
image_2 = Image.open(requests.get(url_2, stream=True).raw)
|
47 |
|
48 |
model_id = "jmtzt/ijepa_vith16_1k"
|
49 |
processor = AutoProcessor.from_pretrained(model_id)
|
50 |
+
model = AutoModel.from_pretrained(model_id)
|
51 |
+
|
52 |
+
def infer(image):
|
53 |
+
inputs = processor(image, return_tensors="pt")
|
54 |
+
outputs = model(**inputs)
|
55 |
+
return outputs.pooler_output
|
56 |
+
|
57 |
+
embed_1 = infer(image_1)
|
58 |
+
embed_2 = infer(image_2)
|
59 |
+
|
60 |
+
similarity = cosine_similarity(embed_1, embed_2)
|
61 |
+
print(similarity)
|
62 |
```
|
63 |
|
64 |
### BibTeX entry and citation info
|