Spaces:
Running
on
Zero
Running
on
Zero
Load using from_pretrained (#1)
Browse files- Load using from_pretrained (80244a20b85237a3175c2fff820e0f3aeabcd603)
Co-authored-by: Niels Rogge <[email protected]>
app.py
CHANGED
@@ -3,12 +3,7 @@ import gradio as gr
|
|
3 |
from ultralytics import YOLOv10
|
4 |
import supervision as sv
|
5 |
import spaces
|
6 |
-
from huggingface_hub import hf_hub_download
|
7 |
|
8 |
-
|
9 |
-
def download_models(model_id):
|
10 |
-
hf_hub_download("kadirnar/Yolov10", filename=f"{model_id}", local_dir=f"./")
|
11 |
-
return f"./{model_id}"
|
12 |
|
13 |
box_annotator = sv.BoxAnnotator()
|
14 |
category_dict = {
|
@@ -34,7 +29,7 @@ category_dict = {
|
|
34 |
@spaces.GPU(duration=200)
|
35 |
def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
36 |
model_path = download_models(model_id)
|
37 |
-
model = YOLOv10(
|
38 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
39 |
detections = sv.Detections.from_ultralytics(results)
|
40 |
|
@@ -55,14 +50,14 @@ def app():
|
|
55 |
model_id = gr.Dropdown(
|
56 |
label="Model",
|
57 |
choices=[
|
58 |
-
"yolov10n
|
59 |
-
"yolov10s
|
60 |
-
"yolov10m
|
61 |
-
"yolov10b
|
62 |
-
"yolov10l
|
63 |
-
"yolov10x
|
64 |
],
|
65 |
-
value="yolov10m
|
66 |
)
|
67 |
image_size = gr.Slider(
|
68 |
label="Image Size",
|
|
|
3 |
from ultralytics import YOLOv10
|
4 |
import supervision as sv
|
5 |
import spaces
|
|
|
6 |
|
|
|
|
|
|
|
|
|
7 |
|
8 |
box_annotator = sv.BoxAnnotator()
|
9 |
category_dict = {
|
|
|
29 |
@spaces.GPU(duration=200)
|
30 |
def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
|
31 |
model_path = download_models(model_id)
|
32 |
+
model = YOLOv10.from_pretrained(f"jameslahm/{model_id}")
|
33 |
results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
|
34 |
detections = sv.Detections.from_ultralytics(results)
|
35 |
|
|
|
50 |
model_id = gr.Dropdown(
|
51 |
label="Model",
|
52 |
choices=[
|
53 |
+
"yolov10n",
|
54 |
+
"yolov10s",
|
55 |
+
"yolov10m",
|
56 |
+
"yolov10b",
|
57 |
+
"yolov10l",
|
58 |
+
"yolov10x",
|
59 |
],
|
60 |
+
value="yolov10m",
|
61 |
)
|
62 |
image_size = gr.Slider(
|
63 |
label="Image Size",
|