praysimanjuntak commited on
Commit
ca16daa
1 Parent(s): 27105e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -39
app.py CHANGED
@@ -3,7 +3,7 @@ import spaces
3
  from huggingface_hub import hf_hub_download
4
 
5
  @spaces.GPU
6
- def yolov9_inference(img_path, model_id, image_size, conf_threshold, iou_threshold):
7
  """
8
  Load a YOLOv9 model, configure it, perform inference on an image, and optionally adjust
9
  the input size and apply test time augmentation.
@@ -20,14 +20,14 @@ def yolov9_inference(img_path, model_id, image_size, conf_threshold, iou_thresho
20
 
21
  # Load the model
22
  model_path = "yolov9-plant.pt"
23
- model = yolov9.load(model_path, device="cpu")
24
 
25
  # Set model parameters
26
  model.conf = conf_threshold
27
  model.iou = iou_threshold
28
 
29
  # Perform inference
30
- results = model(img_path, size=image_size)
31
 
32
  # Optionally, show detection bounding boxes on image
33
  output = results.render()
@@ -40,23 +40,6 @@ def app():
40
  with gr.Row():
41
  with gr.Column():
42
  img_path = gr.Image(type="filepath", label="Image")
43
- model_path = gr.Dropdown(
44
- label="Model",
45
- choices=[
46
- "gelan-c.pt",
47
- "gelan-e.pt",
48
- "yolov9-c.pt",
49
- "yolov9-e.pt",
50
- ],
51
- value="gelan-e.pt",
52
- )
53
- image_size = gr.Slider(
54
- label="Image Size",
55
- minimum=320,
56
- maximum=1280,
57
- step=32,
58
- value=640,
59
- )
60
  conf_threshold = gr.Slider(
61
  label="Confidence Threshold",
62
  minimum=0.1,
@@ -80,8 +63,6 @@ def app():
80
  fn=yolov9_inference,
81
  inputs=[
82
  img_path,
83
- model_path,
84
- image_size,
85
  conf_threshold,
86
  iou_threshold,
87
  ],
@@ -91,16 +72,7 @@ def app():
91
  gr.Examples(
92
  examples=[
93
  [
94
- "data/zidane.jpg",
95
- "gelan-e.pt",
96
- 640,
97
- 0.4,
98
- 0.5,
99
- ],
100
- [
101
- "data/huggingface.jpg",
102
- "yolov9-c.pt",
103
- 640,
104
  0.4,
105
  0.5,
106
  ],
@@ -126,13 +98,6 @@ with gradio_app:
126
  YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
127
  </h1>
128
  """)
129
- gr.HTML(
130
- """
131
- <h3 style='text-align: center'>
132
- Follow me for more!
133
- <a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a> | <a href='https://www.huggingface.co/kadirnar/' target='_blank'>HuggingFace</a>
134
- </h3>
135
- """)
136
  with gr.Row():
137
  with gr.Column():
138
  app()
 
3
  from huggingface_hub import hf_hub_download
4
 
5
  @spaces.GPU
6
+ def yolov9_inference(img_path, conf_threshold, iou_threshold):
7
  """
8
  Load a YOLOv9 model, configure it, perform inference on an image, and optionally adjust
9
  the input size and apply test time augmentation.
 
20
 
21
  # Load the model
22
  model_path = "yolov9-plant.pt"
23
+ model = yolov9.load(model_path, device="cuda:0")
24
 
25
  # Set model parameters
26
  model.conf = conf_threshold
27
  model.iou = iou_threshold
28
 
29
  # Perform inference
30
+ results = model(img_path, size=640)
31
 
32
  # Optionally, show detection bounding boxes on image
33
  output = results.render()
 
40
  with gr.Row():
41
  with gr.Column():
42
  img_path = gr.Image(type="filepath", label="Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  conf_threshold = gr.Slider(
44
  label="Confidence Threshold",
45
  minimum=0.1,
 
63
  fn=yolov9_inference,
64
  inputs=[
65
  img_path,
 
 
66
  conf_threshold,
67
  iou_threshold,
68
  ],
 
72
  gr.Examples(
73
  examples=[
74
  [
75
+ "data/apple_d1.jpg",
 
 
 
 
 
 
 
 
 
76
  0.4,
77
  0.5,
78
  ],
 
98
  YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
99
  </h1>
100
  """)
 
 
 
 
 
 
 
101
  with gr.Row():
102
  with gr.Column():
103
  app()