eeshawn commited on
Commit
da44c62
·
1 Parent(s): f111195

update model path

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
2
  from ultralyticsplus import YOLO
 
3
 
4
  def yolov8_inference(
5
- image: gr.inputs.Image = None,
6
  model_path = "eeshawn11/naruto_hand_seal_detection",
7
- conf_threshold: gr.inputs.Slider = 0.50,
8
- iou_threshold: gr.inputs.Slider = 0.45,
9
  ):
10
  """
11
  YOLOv8 inference function
@@ -17,11 +18,13 @@ def yolov8_inference(
17
  Returns:
18
  Rendered image
19
  """
20
- model = YOLO(model_path)
 
21
  model.conf = conf_threshold
22
  model.iou = iou_threshold
23
  results = model.predict(image, return_outputs=True)
24
  object_prediction_list = []
 
25
  for _, image_results in enumerate(results):
26
  if len(image_results)!=0:
27
  image_predictions_in_xyxy_format = image_results['det']
@@ -36,27 +39,30 @@ def yolov8_inference(
36
  score = pred[4]
37
  category_name = model.model.names[int(pred[5])]
38
  category_id = pred[5]
39
- object_prediction = ObjectPrediction(
40
- bbox=bbox,
41
- category_id=int(category_id),
42
- score=score,
43
- category_name=category_name,
44
- )
45
- object_prediction_list.append(object_prediction)
 
46
 
47
- image = read_image(image)
48
- output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
49
- return output_image['image']
 
 
50
 
51
 
52
  inputs = [
53
  # gr.inputs.Image(type="filepath", label="Input Image"),
54
  gr.Image(source="upload", type="pil", label="Image Upload", interactive=True),
55
- gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.5, step=0.05, label="Confidence Threshold"),
56
- gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
57
  ]
58
 
59
- outputs = gr.outputs.Image(type="filepath", label="Output Image")
60
  title = "Naruto Hand Seal Detection with YOLOv8"
61
 
62
  myapp = gr.Interface(
 
1
  import gradio as gr
2
  from ultralyticsplus import YOLO
3
+ from ultralytics.yolo.utils.plotting import Annotator
4
 
5
  def yolov8_inference(
6
+ image: gr.Image = None,
7
  model_path = "eeshawn11/naruto_hand_seal_detection",
8
+ conf_threshold: gr.Slider = 0.50,
9
+ iou_threshold: gr.Slider = 0.45,
10
  ):
11
  """
12
  YOLOv8 inference function
 
18
  Returns:
19
  Rendered image
20
  """
21
+ # model = YOLO(model_path)
22
+ model = YOLO("ultralyticsplus/yolov8s")
23
  model.conf = conf_threshold
24
  model.iou = iou_threshold
25
  results = model.predict(image, return_outputs=True)
26
  object_prediction_list = []
27
+ annotator = Annotator(image)
28
  for _, image_results in enumerate(results):
29
  if len(image_results)!=0:
30
  image_predictions_in_xyxy_format = image_results['det']
 
39
  score = pred[4]
40
  category_name = model.model.names[int(pred[5])]
41
  category_id = pred[5]
42
+ annotator.box_label(bbox, f"{category_name} {score}")
43
+ # object_prediction = ObjectPrediction(
44
+ # bbox=bbox,
45
+ # category_id=int(category_id),
46
+ # score=score,
47
+ # category_name=category_name,
48
+ # )
49
+ # object_prediction_list.append(object_prediction)
50
 
51
+ # image = read_image(image)
52
+ # output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
53
+
54
+ # return output_image['image']
55
+ return annotator.result()
56
 
57
 
58
  inputs = [
59
  # gr.inputs.Image(type="filepath", label="Input Image"),
60
  gr.Image(source="upload", type="pil", label="Image Upload", interactive=True),
61
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.5, step=0.05, label="Confidence Threshold"),
62
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
63
  ]
64
 
65
+ outputs = gr.Image(type="filepath", label="Output Image")
66
  title = "Naruto Hand Seal Detection with YOLOv8"
67
 
68
  myapp = gr.Interface(