Make code example more clear
Browse files
README.md
CHANGED
@@ -33,13 +33,19 @@ Here is how to use this model to classify an image of the COCO 2017 dataset into
|
|
33 |
from transformers import AutoFeatureExtractor, DeiTForImageClassificationWithTeacher
|
34 |
from PIL import Image
|
35 |
import requests
|
|
|
36 |
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
37 |
image = Image.open(requests.get(url, stream=True).raw)
|
|
|
38 |
feature_extractor = AutoFeatureExtractor.from_pretrained('facebook/deit-base-distilled-patch16-224')
|
39 |
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-base-distilled-patch16-224')
|
|
|
40 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
|
|
|
|
41 |
outputs = model(**inputs)
|
42 |
logits = outputs.logits
|
|
|
43 |
# model predicts one of the 1000 ImageNet classes
|
44 |
predicted_class_idx = logits.argmax(-1).item()
|
45 |
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
|
|
33 |
from transformers import AutoFeatureExtractor, DeiTForImageClassificationWithTeacher
|
34 |
from PIL import Image
|
35 |
import requests
|
36 |
+
|
37 |
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
38 |
image = Image.open(requests.get(url, stream=True).raw)
|
39 |
+
|
40 |
feature_extractor = AutoFeatureExtractor.from_pretrained('facebook/deit-base-distilled-patch16-224')
|
41 |
model = DeiTForImageClassificationWithTeacher.from_pretrained('facebook/deit-base-distilled-patch16-224')
|
42 |
+
|
43 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
44 |
+
|
45 |
+
# forward pass
|
46 |
outputs = model(**inputs)
|
47 |
logits = outputs.logits
|
48 |
+
|
49 |
# model predicts one of the 1000 ImageNet classes
|
50 |
predicted_class_idx = logits.argmax(-1).item()
|
51 |
print("Predicted class:", model.config.id2label[predicted_class_idx])
|