linhcuem commited on
Commit
f3958f6
1 Parent(s): e5997ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -33
app.py CHANGED
@@ -19,7 +19,7 @@ image_path = [['test_images/2a998cfb0901db5f8210.jpg','linhcuem/chamdiem_yolov8_
19
  ['test_images/ee106392e56837366e79.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45], ['test_images/f88d2214a4ee76b02fff.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45]]
20
 
21
  # Load YOLO model
22
- model = YOLO('linhcuem/chamdiem_yolov8_ver10')
23
 
24
  ###################################################
25
  def yolov8_img_inference(
@@ -30,36 +30,45 @@ def yolov8_img_inference(
30
  iou_threshold: gr.inputs.Slider = 0.45,
31
  ):
32
  model = YOLO(model_path)
33
- model.conf = conf_threshold
34
- model.iou = iou_threshold
35
- results = model.predict(image, imgsz=image_size, return_outputs=True)
 
 
 
 
 
 
 
 
 
36
  # results = model.predict(image)
37
- object_prediction_list = []
38
- for _, image_results in enumerate(results):
39
- if len(image_results)!=0:
40
- image_predictions_in_xyxy_format = image_results['det']
41
- for pred in image_predictions_in_xyxy_format:
42
- x1, y1, x2, y2 = (
43
- int(pred[0]),
44
- int(pred[1]),
45
- int(pred[2]),
46
- int(pred[3]),
47
- )
48
- bbox = [x1, y1, x2, y2]
49
- score = pred[4]
50
- category_name = model.model.names[int(pred[5])]
51
- category_id = pred[5]
52
- object_prediction = ObjectPrediction(
53
- bbox=bbox,
54
- category_id=int(category_id),
55
- score=score,
56
- category_name=category_name,
57
- )
58
- object_prediction_list.append(object_prediction)
59
 
60
- image = read_image(image)
61
- output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
62
- return output_image['image']
63
  # render = render_result(model=model, image=image, result=results[0])
64
 
65
 
@@ -87,9 +96,9 @@ interface_image = gr.Interface(
87
  theme='huggingface'
88
  )
89
 
90
- gr.TabbedInterface(
91
- [interface_image],
92
- tab_names=['Image inference']
93
- ).queue().launch()
94
 
95
  interface_image.launch(debug=True, enable_queue=True)
 
19
  ['test_images/ee106392e56837366e79.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45], ['test_images/f88d2214a4ee76b02fff.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45]]
20
 
21
  # Load YOLO model
22
+ # model = YOLO('linhcuem/chamdiem_yolov8_ver10')
23
 
24
  ###################################################
25
  def yolov8_img_inference(
 
30
  iou_threshold: gr.inputs.Slider = 0.45,
31
  ):
32
  model = YOLO(model_path)
33
+ # model.conf = conf_threshold
34
+ # model.iou = iou_threshold
35
+ model.overrides['conf'] = conf_threshold
36
+ model.overrides['iou'] = iou_threshold
37
+ model.overrides['agnostic_nms'] = False
38
+ model.overrides['max_det'] = 1000
39
+ image = read_image
40
+ results = model.predict(image)
41
+ results = render_result(model=model, image=image, result=results[0])
42
+
43
+
44
+ # results = model.predict(image, imgsz=image_size, return_outputs=True)
45
  # results = model.predict(image)
46
+ # object_prediction_list = []
47
+ # for _, image_results in enumerate(results):
48
+ # if len(image_results)!=0:
49
+ # image_predictions_in_xyxy_format = image_results['det']
50
+ # for pred in image_predictions_in_xyxy_format:
51
+ # x1, y1, x2, y2 = (
52
+ # int(pred[0]),
53
+ # int(pred[1]),
54
+ # int(pred[2]),
55
+ # int(pred[3]),
56
+ # )
57
+ # bbox = [x1, y1, x2, y2]
58
+ # score = pred[4]
59
+ # category_name = model.model.names[int(pred[5])]
60
+ # category_id = pred[5]
61
+ # object_prediction = ObjectPrediction(
62
+ # bbox=bbox,
63
+ # category_id=int(category_id),
64
+ # score=score,
65
+ # category_name=category_name,
66
+ # )
67
+ # object_prediction_list.append(object_prediction)
68
 
69
+ # image = read_image(image)
70
+ # output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
71
+ # return output_image['image']
72
  # render = render_result(model=model, image=image, result=results[0])
73
 
74
 
 
96
  theme='huggingface'
97
  )
98
 
99
+ # gr.TabbedInterface(
100
+ # [interface_image],
101
+ # tab_names=['Image inference']
102
+ # ).queue().launch()
103
 
104
  interface_image.launch(debug=True, enable_queue=True)