@@ -164,14 +164,14 @@ First we'll need an image to do inference on. Here we load a picture of a leaf f
164164>> > import requests
165165>> > from PIL import Image
166166>> > 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'
168168>> > image = Image.open(requests.get(url, stream = True ).raw)
169169>> > image
170170```
171171
172172Here's the image we loaded:
173173
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" />
175175
176176Now, we'll create our model and transforms again. This time, we make sure to set our model in evaluation mode.
177177
@@ -211,7 +211,7 @@ Now we'll find the top 5 predicted class indexes and values using `torch.topk`.
211211``` py
212212>> > values, indices = torch.topk(probabilities, 5 )
213213>> > indices
214- tensor([162 , 166 , 161 , 164 , 167 ])
214+ tensor([281 , 282 , 285 , 673 , 670 ])
215215```
216216
217217If 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
220220>> > IMAGENET_1k_URL = ' https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt'
221221>> > IMAGENET_1k_LABELS = requests.get(IMAGENET_1k_URL ).text.strip().split(' \n ' )
222222>> > [{' 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 }]
228228```
0 commit comments