kadirnar commited on
Commit
f1c31b8
1 Parent(s): e5008ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def yolov9_inference(model_path, device, conf_threshold, iou_threshold, img_path, size=640):
5
+ """
6
+ Load a YOLOv9 model, configure it, perform inference on an image, and optionally adjust
7
+ the input size and apply test time augmentation.
8
+
9
+ :param model_path: Path to the YOLOv9 model file.
10
+ :param device: Computation device, 'cpu' or 'cuda'.
11
+ :param conf_threshold: Confidence threshold for NMS.
12
+ :param iou_threshold: IoU threshold for NMS.
13
+ :param img_path: Path to the image file.
14
+ :param size: Optional, input size for inference.
15
+ :return: A tuple containing the detections (boxes, scores, categories) and the results object for further actions like displaying.
16
+ """
17
+ # Import YOLOv9
18
+ import yolov9
19
+
20
+ # Load the model
21
+ model = yolov9.load(model_path, device=device)
22
+
23
+ # Set model parameters
24
+ model.conf = conf_threshold
25
+ model.iou = iou_threshold
26
+
27
+ # Perform inference
28
+ results = model(img_path, size=size)
29
+
30
+ # Optionally, show detection bounding boxes on image
31
+ save_path = 'output/'
32
+ results.save(labels=True, save_dir=save_path)
33
+
34
+
35
+ return save_path + 'elon.jpg'
36
+
37
+
38
+ inputs = [
39
+ gr.Image(label="Input Image"),
40
+ gr.Dropdown(
41
+ label="Model",
42
+ choices=[
43
+ "gelan-c.pt",
44
+ "gelan-e.pt",
45
+ "yolov9-c.pt",
46
+ "yolov9-e.pt",
47
+ ],
48
+ value="gelan-e.pt",
49
+ ),
50
+ gr.Slider(minimum=320, maximum=1280, value=1280, step=32, label="Image Size"),
51
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"),
52
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
53
+ ]
54
+
55
+ outputs = gr.Image(type="filepath", label="Output Image")
56
+ title = "YOLOv9"
57
+
58
+ demo_app = gr.Interface(
59
+ fn=yolov9_inference,
60
+ inputs=inputs,
61
+ outputs=outputs,
62
+ title=title,
63
+ )
64
+ demo_app.launch(debug=True)