trevorhobenshield
commited on
Commit
•
cf14453
1
Parent(s):
0ee27ca
Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,43 @@ datasets:
|
|
7 |
- imagenet-22k
|
8 |
---
|
9 |
|
10 |
-
See: [https://huggingface.co/timm/eva02_tiny_patch14_336.mim_in22k_ft_in1k](https://huggingface.co/timm/eva02_tiny_patch14_336.mim_in22k_ft_in1k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
- imagenet-22k
|
8 |
---
|
9 |
|
10 |
+
See: [https://huggingface.co/timm/eva02_tiny_patch14_336.mim_in22k_ft_in1k](https://huggingface.co/timm/eva02_tiny_patch14_336.mim_in22k_ft_in1k)
|
11 |
+
|
12 |
+
```python
|
13 |
+
from urllib.request import urlopen
|
14 |
+
|
15 |
+
import einops
|
16 |
+
import numpy as np
|
17 |
+
import onnxruntime
|
18 |
+
from PIL import Image
|
19 |
+
|
20 |
+
def softmax(x):
|
21 |
+
y = np.exp(x - np.max(x))
|
22 |
+
return y / y.sum(axis=0)
|
23 |
+
|
24 |
+
IMG_URL = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
25 |
+
IN1K_CLASSES_URL = 'https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt'
|
26 |
+
|
27 |
+
session = onnxruntime.InferenceSession('eva02_tiny_patch14_336.mim_in22k_ft_in1k.ort')
|
28 |
+
# session = onnxruntime.InferenceSession('eva02_tiny_patch14_336.mim_in22k_ft_in1k.onnx')
|
29 |
+
|
30 |
+
labels = urlopen(IN1K_CLASSES_URL).read().decode().splitlines()
|
31 |
+
img = np.array(
|
32 |
+
Image.open(urlopen(IMG_URL))
|
33 |
+
.resize(session._sess.inputs_meta[0].shape[2:])
|
34 |
+
)
|
35 |
+
|
36 |
+
# e.g. in1k norm stats
|
37 |
+
mean = .485, .456, .406
|
38 |
+
sd = .229, .224, .225
|
39 |
+
img = (img / 255. - mean) / sd
|
40 |
+
|
41 |
+
# to clearly illustrate format ort expects
|
42 |
+
img = einops.rearrange(img, 'h w c -> 1 c h w').astype(np.float32)
|
43 |
+
out = session.run(None, {session.get_inputs()[0].name: img})
|
44 |
+
|
45 |
+
out = softmax(out[0][0])
|
46 |
+
topk = np.argsort(out)[::-1][:5]
|
47 |
+
for i in topk:
|
48 |
+
print(f'{out[i]:.2f}', labels[i])
|
49 |
+
```
|