linhcuem commited on
Commit
e29b3e1
1 Parent(s): cdc58c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -30
app.py CHANGED
@@ -32,35 +32,35 @@ def yolov8_img_inference(
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
  return render
66
 
@@ -83,7 +83,7 @@ interface_image = gr.Interface(
83
  outputs=outputs_image,
84
  title=title,
85
  examples=image_path,
86
- cache_examples=False,
87
  theme='huggingface'
88
  )
89
 
@@ -92,4 +92,4 @@ gr.TabbedInterface(
92
  tab_names=['Image inference']
93
  ).queue().launch()
94
 
95
- # interface_image.launch(debug=True, enable_queue=True)
 
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
  return render
66
 
 
83
  outputs=outputs_image,
84
  title=title,
85
  examples=image_path,
86
+ cache_examples=True,
87
  theme='huggingface'
88
  )
89
 
 
92
  tab_names=['Image inference']
93
  ).queue().launch()
94
 
95
+ interface_image.launch(debug=True, enable_queue=True)