Spaces:
Sleeping
Sleeping
Pipeline
Browse files
app.py
CHANGED
|
@@ -1,24 +1,15 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
from PIL import Image
|
| 3 |
-
import torch
|
| 4 |
-
import torch.nn.functional as F
|
| 5 |
|
| 6 |
-
device = torch.device("cpu")
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
processor = EfficientNetImageProcessor.from_pretrained("models/dennisjooo/Birds-Classifier-EfficientNetB2")
|
| 10 |
-
model = EfficientNetForImageClassification.from_pretrained("models/dennisjooo/Birds-Classifier-EfficientNetB2").to(device)
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def predict(image):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
predicted_class_prob = F.softmax(logits, dim=-1).detach().cpu().numpy().max()
|
| 18 |
-
predicted_class_idx = logits.argmax(-1).item()
|
| 19 |
-
label = model.config.id2label[predicted_class_idx].split(",")[0]
|
| 20 |
-
return {label: float(predicted_class_prob)}
|
| 21 |
-
|
| 22 |
|
| 23 |
import gradio as gr
|
| 24 |
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
from PIL import Image
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
#device = torch.device("cpu")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
#processor = EfficientNetImageProcessor.from_pretrained("models/dennisjooo/Birds-Classifier-EfficientNetB2")
|
| 7 |
+
#model = EfficientNetForImageClassification.from_pretrained("models/dennisjooo/Birds-Classifier-EfficientNetB2").to(device)
|
| 8 |
|
| 9 |
def predict(image):
|
| 10 |
+
pipe = pipeline("image-classification", model="models/dennisjooo/Birds-Classifier-EfficientNetB2")
|
| 11 |
+
predictions = pipe(img)
|
| 12 |
+
return {p["label"]: p["score"] for p in predictions}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
import gradio as gr
|
| 15 |
|