Update README.md
Browse files
README.md
CHANGED
@@ -27,12 +27,9 @@ license: apache-2.0
|
|
27 |
### Image Embeddings
|
28 |
|
29 |
```python
|
30 |
-
from torchvision.transforms import v2
|
31 |
from PIL import Image
|
32 |
-
import requests
|
33 |
import torch
|
34 |
import timm
|
35 |
-
import io
|
36 |
|
37 |
# load model from the hub
|
38 |
model = timm.create_model(
|
@@ -40,7 +37,13 @@ model = timm.create_model(
|
|
40 |
pretrained=True,
|
41 |
).eval()
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
```
|
45 |
|
46 |
## Citation
|
|
|
27 |
### Image Embeddings
|
28 |
|
29 |
```python
|
|
|
30 |
from PIL import Image
|
|
|
31 |
import torch
|
32 |
import timm
|
|
|
33 |
|
34 |
# load model from the hub
|
35 |
model = timm.create_model(
|
|
|
37 |
pretrained=True,
|
38 |
).eval()
|
39 |
|
40 |
+
# get model specific transforms (normalization, resize)
|
41 |
+
data_config = timm.data.resolve_model_data_config(model)
|
42 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
43 |
+
|
44 |
+
img = Image.open(...)
|
45 |
+
data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
|
46 |
+
output = model(data) # output is a (batch_size, num_features) shaped tensor
|
47 |
```
|
48 |
|
49 |
## Citation
|