Spaces:
Sleeping
Sleeping
srishti-hf1110
commited on
Commit
•
af0251b
1
Parent(s):
0e01ce3
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/drive/1XX8pCT291obpzL4fc1vu5L_HTG027lle
|
8 |
"""
|
9 |
-
import gradio
|
10 |
import datasets
|
11 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
12 |
|
@@ -19,7 +19,8 @@ labels = dataset['train'].features['labels'].names
|
|
19 |
|
20 |
def classify(im):
|
21 |
features = feature_extractor(im, return_tensors='pt')
|
22 |
-
|
|
|
23 |
probability = torch.nn.functional.softmax(logits, dim=-1)
|
24 |
probs = probability[0].detach().numpy()
|
25 |
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/drive/1XX8pCT291obpzL4fc1vu5L_HTG027lle
|
8 |
"""
|
9 |
+
import gradio as gr
|
10 |
import datasets
|
11 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
12 |
|
|
|
19 |
|
20 |
def classify(im):
|
21 |
features = feature_extractor(im, return_tensors='pt')
|
22 |
+
with torch.no_grad():
|
23 |
+
logits = model(features["pixel_values"])[-1]
|
24 |
probability = torch.nn.functional.softmax(logits, dim=-1)
|
25 |
probs = probability[0].detach().numpy()
|
26 |
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|