Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,17 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoFeatureExtractor, SwinForImageClassification
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
|
5 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
6 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
7 |
+
|
8 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("microsoft/swin-small-patch4-window7-224")
|
9 |
+
model = SwinForImageClassification.from_pretrained("microsoft/swin-small-patch4-window7-224")
|
10 |
+
|
11 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
12 |
+
outputs = model(**inputs)
|
13 |
+
logits = outputs.logits
|
14 |
+
# model predicts one of the 1000 ImageNet classes
|
15 |
+
predicted_class_idx = logits.argmax(-1).item()
|
16 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
17 |
+
|