alanchen1115 commited on
Commit
c04da13
·
verified ·
1 Parent(s): d25cfc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -8,10 +8,17 @@ examples=[["photo/a.jpg","Image1"],["photo/b.jpg","Image2"],
8
  ["photo/g.jpg","Image7"],["photo/h.jpg","Image8"]]
9
 
10
 
11
- def detect_objects_on_image(image_path):
12
  image = cv2.imread(image_path)
13
  model = YOLO("best.pt")
14
- results = model.predict(image_path, conf=0.3, iou=0.5)
 
 
 
 
 
 
 
15
  result = results[0]
16
  output = []
17
  for box in result.boxes:
@@ -45,7 +52,11 @@ outputs_image = [
45
  ]
46
  demo = gr.Interface(
47
  fn=detect_objects_on_image,
48
- inputs=inputs_image,
 
 
 
 
49
  outputs=outputs_image,
50
  title="Yolov8 Custom Object Detection",
51
  examples=examples,
 
8
  ["photo/g.jpg","Image7"],["photo/h.jpg","Image8"]]
9
 
10
 
11
+ def detect_objects_on_image(image_path, conf_threshold, iou_threshold):
12
  image = cv2.imread(image_path)
13
  model = YOLO("best.pt")
14
+ results = model.predict(
15
+ source=image,
16
+ conf=conf_threshold,
17
+ iou=iou_threshold,
18
+ show_labels=True,
19
+ show_conf=True,
20
+ imgsz=640,
21
+ )
22
  result = results[0]
23
  output = []
24
  for box in result.boxes:
 
52
  ]
53
  demo = gr.Interface(
54
  fn=detect_objects_on_image,
55
+ inputs=[
56
+ gr.Image(type="pil", label="Upload Image"),
57
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
58
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
59
+ ],
60
  outputs=outputs_image,
61
  title="Yolov8 Custom Object Detection",
62
  examples=examples,