Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
-
from ultralytics
|
| 4 |
import torch
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
MODEL_PATH = "best.pt"
|
| 7 |
-
model =
|
| 8 |
-
model.eval()
|
| 9 |
-
|
| 10 |
CLASS_NAMES = ["ax", "co", "sa"]
|
| 11 |
|
| 12 |
# ------------------------
|
| 13 |
# prediction
|
| 14 |
# ------------------------
|
| 15 |
def predict_orientation(image: Image.Image):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
])
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
probs = torch.softmax(outputs, dim=1)
|
| 26 |
-
conf, pred = torch.max(probs, 1)
|
| 27 |
-
orientation = CLASS_NAMES[pred.item()]
|
| 28 |
-
confidence = round(conf.item(), 2)
|
| 29 |
-
|
| 30 |
return f"Orientation: {orientation} | Confidence: {confidence}"
|
| 31 |
|
| 32 |
# ------------------------
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# ------------------------
|
| 7 |
+
# تحميل الموديل (YOLOv11 classification .pt)
|
| 8 |
+
# ------------------------
|
| 9 |
MODEL_PATH = "best.pt"
|
| 10 |
+
model = YOLO(MODEL_PATH)
|
|
|
|
|
|
|
| 11 |
CLASS_NAMES = ["ax", "co", "sa"]
|
| 12 |
|
| 13 |
# ------------------------
|
| 14 |
# prediction
|
| 15 |
# ------------------------
|
| 16 |
def predict_orientation(image: Image.Image):
|
| 17 |
+
# inference باستخدام Ultralytics
|
| 18 |
+
results = model.predict(source=image, device="cpu", imgsz=224, verbose=False)
|
| 19 |
+
|
| 20 |
+
# استخراج الاحتمالات
|
| 21 |
+
probs = results[0].probs.data.cpu()
|
| 22 |
+
pred = torch.argmax(probs)
|
| 23 |
+
orientation = CLASS_NAMES[pred.item()]
|
| 24 |
+
confidence = round(probs[pred].item(), 2)
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return f"Orientation: {orientation} | Confidence: {confidence}"
|
| 27 |
|
| 28 |
# ------------------------
|