Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,22 @@
|
|
1 |
-
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
vision_classifier = pipeline(task="image-classification")
|
|
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
vision_classifier = pipeline(task="image-classification")
|
4 |
+
result = vision_classifier(images="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")
|
5 |
|
6 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
7 |
+
import torch
|
8 |
+
from datasets import load_dataset
|
9 |
|
10 |
+
dataset = load_dataset("huggingface/cats-image")
|
11 |
+
image = dataset["test"]["image"][0]
|
12 |
+
|
13 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
|
14 |
+
model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16-224")
|
15 |
+
|
16 |
+
inputs = feature_extractor(image, return_tensors="pt")
|
17 |
+
|
18 |
+
with torch.no_grad():
|
19 |
+
logits = model(**inputs).logits
|
20 |
+
|
21 |
+
predicted_label = logits.argmax(-1).item()
|
22 |
+
print(model.config.id2label[predicted_label])
|