kadirnar nielsr HF staff commited on
Commit
58175b2
1 Parent(s): 534176a

Load using from_pretrained (#1)

Browse files

- Load using from_pretrained (80244a20b85237a3175c2fff820e0f3aeabcd603)


Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +8 -13
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(model_path)
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.pt",
59
- "yolov10s.pt",
60
- "yolov10m.pt",
61
- "yolov10b.pt",
62
- "yolov10l.pt",
63
- "yolov10x.pt",
64
  ],
65
- value="yolov10m.pt",
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",