itsanurag commited on
Commit
a4392bd
·
verified ·
1 Parent(s): b000446

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -1,23 +1,27 @@
1
  import gradio as gr
 
 
 
2
  import torch
3
- from ultralyticsplus import YOLO, render_result
 
 
4
 
5
 
6
- def yoloV9_func(image: gr.Image = None,
7
  image_size: int = 640,
8
  conf_threshold: float = 0.4,
9
- iou_threshold: float = 0.50):
10
- """This function performs YOLOv9 object detection on the given image.
11
-
12
  Args:
13
- image (gr.inputs.Image, optional): Input image to detect objects on. Defaults to None.
14
- image_size (gr.inputs.Slider, optional): Desired image size for the model. Defaults to 640.
15
- conf_threshold (gr.inputs.Slider, optional): Confidence threshold for object detection. Defaults to 0.4.
16
- iou_threshold (gr.inputs.Slider, optional): Intersection over Union threshold for object detection. Defaults to 0.50.
17
  """
18
  # Load the YOLOv8 model from the 'best.pt' checkpoint
19
- model_path = "best_model.pt"
20
- model = YOLO(model_path)
21
 
22
  # Perform object detection on the input image using the YOLOv8 model
23
  results = model.predict(image,
@@ -32,35 +36,33 @@ def yoloV9_func(image: gr.Image = None,
32
  print("Probability:", box.conf)
33
 
34
  # Render the output image with bounding boxes around detected objects
35
- render = render_result(model=model, image=image, result=results[0])
36
  return render
37
 
38
 
39
  inputs = [
40
  gr.Image(type="filepath", label="Input Image"),
41
- gr.Slider(minimum=320, maximum=1280, step=32, label="Image Size"),
42
  gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="Confidence Threshold"),
43
  gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="IOU Threshold"),
44
  ]
45
 
46
-
47
  outputs = gr.Image(type="filepath", label="Output Image")
48
 
49
- title = "CUSTOM yolov9 model for room cleanliness"
50
-
51
 
52
  examples = [['one.jpg', 640, 0.5, 0.7],
53
  ['two.jpg', 640, 0.5, 0.6],
54
  ['three.jpg', 640, 0.5, 0.8]]
55
 
56
  yolo_app = gr.Interface(
57
- fn=yoloV9_func,
58
  inputs=inputs,
59
  outputs=outputs,
60
  title=title,
61
  examples=examples,
62
- cache_examples=True,
63
  )
64
 
65
  # Launch the Gradio interface in debug mode with queue enabled
66
- yolo_app.launch(debug=True, enable_queue=True)
 
1
  import gradio as gr
2
+
3
+ from ultralytics import YOLO
4
+ model = YOLO('./best_model.pt') # load your custom trained model
5
  import torch
6
+ #from ultralyticsplus import render_result
7
+ from render import custom_render_result
8
+
9
 
10
 
11
+ def yoloV8_func(image: gr.Image = None,
12
  image_size: int = 640,
13
  conf_threshold: float = 0.4,
14
+ iou_threshold: float = 0.5):
15
+ """This function performs YOLOv8 object detection on the given image.
 
16
  Args:
17
+ image (gr.Image, optional): Input image to detect objects on. Defaults to None.
18
+ image_size (int, optional): Desired image size for the model. Defaults to 640.
19
+ conf_threshold (float, optional): Confidence threshold for object detection. Defaults to 0.4.
20
+ iou_threshold (float, optional): Intersection over Union threshold for object detection. Defaults to 0.50.
21
  """
22
  # Load the YOLOv8 model from the 'best.pt' checkpoint
23
+ model_path = "yolov5s.pt"
24
+ # model = torch.hub.load('ultralytics/yolov8', 'custom', path='/content/best.pt', force_reload=True, trust_repo=True)
25
 
26
  # Perform object detection on the input image using the YOLOv8 model
27
  results = model.predict(image,
 
36
  print("Probability:", box.conf)
37
 
38
  # Render the output image with bounding boxes around detected objects
39
+ render = custom_render_result(model=model, image=image, result=results[0])
40
  return render
41
 
42
 
43
  inputs = [
44
  gr.Image(type="filepath", label="Input Image"),
45
+ gr.Slider(minimum=320, maximum=1280, step=32, label="Image Size", value=640),
46
  gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="Confidence Threshold"),
47
  gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="IOU Threshold"),
48
  ]
49
 
 
50
  outputs = gr.Image(type="filepath", label="Output Image")
51
 
52
+ title = "YOLOv8 101: Custom Object Detection on meter"
 
53
 
54
  examples = [['one.jpg', 640, 0.5, 0.7],
55
  ['two.jpg', 640, 0.5, 0.6],
56
  ['three.jpg', 640, 0.5, 0.8]]
57
 
58
  yolo_app = gr.Interface(
59
+ fn=yoloV8_func,
60
  inputs=inputs,
61
  outputs=outputs,
62
  title=title,
63
  examples=examples,
64
+ cache_examples=False,
65
  )
66
 
67
  # Launch the Gradio interface in debug mode with queue enabled
68
+ yolo_app.launch(debug=True,share=True).queue()