@@ -164,14 +164,14 @@ First we'll need an image to do inference on. Here we load a picture of a leaf f
164
164
>> > import requests
165
165
>> > from PIL import Image
166
166
>> > from io import BytesIO
167
- >> > url = ' https://datasets-server. huggingface.co/assets/imagenet-1k/--/default/test/12/image/image .jpg'
167
+ >> > url = ' https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/timm/cat .jpg'
168
168
>> > image = Image.open(requests.get(url, stream = True ).raw)
169
169
>> > image
170
170
```
171
171
172
172
Here's the image we loaded:
173
173
174
- <img src = " https://datasets-server. huggingface.co/assets/imagenet-1k/--/default/test/12/image/image .jpg" alt = " An Image from a link" width = " 300" />
174
+ <img src = " https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/timm/cat .jpg" alt = " An Image from a link" width = " 300" />
175
175
176
176
Now, we'll create our model and transforms again. This time, we make sure to set our model in evaluation mode.
177
177
@@ -211,7 +211,7 @@ Now we'll find the top 5 predicted class indexes and values using `torch.topk`.
211
211
``` py
212
212
>> > values, indices = torch.topk(probabilities, 5 )
213
213
>> > indices
214
- tensor([162 , 166 , 161 , 164 , 167 ])
214
+ tensor([281 , 282 , 285 , 673 , 670 ])
215
215
```
216
216
217
217
If we check the imagenet labels for the top index, we can see what the model predicted...
@@ -220,9 +220,9 @@ If we check the imagenet labels for the top index, we can see what the model pre
220
220
>> > IMAGENET_1k_URL = ' https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt'
221
221
>> > IMAGENET_1k_LABELS = requests.get(IMAGENET_1k_URL ).text.strip().split(' \n ' )
222
222
>> > [{' label' : IMAGENET_1k_LABELS [idx], ' value' : val.item()} for val, idx in zip (values, indices)]
223
- [{' label' : ' beagle ' , ' value' : 0.8486220836639404 },
224
- {' label' : ' Walker_hound, Walker_foxhound ' , ' value' : 0.03753996267914772 },
225
- {' label' : ' basset, basset_hound ' , ' value' : 0.024628572165966034 },
226
- {' label' : ' bluetick ' , ' value' : 0.010317106731235981 },
227
- {' label' : ' English_foxhound ' , ' value' : 0.006958036217838526 }]
223
+ [{' label' : ' tabby, tabby_cat ' , ' value' : 0.5101025700569153 },
224
+ {' label' : ' tiger_cat ' , ' value' : 0.22490699589252472 },
225
+ {' label' : ' Egyptian_cat ' , ' value' : 0.1835290789604187 },
226
+ {' label' : ' mouse, computer_mouse ' , ' value' : 0.006752475164830685 },
227
+ {' label' : ' motor_scooter, scooter ' , ' value' : 0.004942195490002632 }]
228
228
```
0 commit comments