linhcuem commited on
Commit
b2654b1
·
1 Parent(s): 5627083

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -56,20 +56,7 @@ def yolov8_img_inference(
56
  # count 'car' objects in the results
57
  # count_result = results[0].boxes.cls[0].item()
58
  # count_result = results[0].boxes.cls.tolist()
59
- object_counts = {x: 0 for x in names}
60
- for prediction in predictions:
61
- for c in prediction.boxes.cls:
62
- c = int(c)
63
- if c in names:
64
- object_counts[c] += 1
65
- elif c not in names:
66
- object_counts[c] = 1
67
-
68
- present_objects = object_counts.copy()
69
 
70
- for i in object_counts:
71
- if object_counts[i] < 1:
72
- present_objects.pop(i)
73
 
74
  # clist= results[0].boxes.cls.tolist()
75
  # cls = set()
@@ -77,7 +64,7 @@ def yolov8_img_inference(
77
  # cls.add(model.names[int(cno)])
78
 
79
  # count_result = results.pandas().xyxy[0].value_counts('name')
80
- return render, present_objects
81
  # results = model.predict(image, imgsz=image_size, return_outputs=True)
82
  # results = model.predict(image)
83
  # object_prediction_list = []
@@ -107,7 +94,23 @@ def yolov8_img_inference(
107
  # output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
108
  # return output_image['image']
109
  # render = render_result(model=model, image=image, result=results[0])
110
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
 
113
 
@@ -127,7 +130,7 @@ inputs_image = [
127
  title = "Tất cả do anh Đạt"
128
 
129
  interface_image = gr.Interface(
130
- fn=yolov8_img_inference,
131
  inputs=inputs_image,
132
  outputs=[gr.Image(type="pil"),gr.Textbox(show_label=False)],
133
  title=title,
 
56
  # count 'car' objects in the results
57
  # count_result = results[0].boxes.cls[0].item()
58
  # count_result = results[0].boxes.cls.tolist()
 
 
 
 
 
 
 
 
 
 
59
 
 
 
 
60
 
61
  # clist= results[0].boxes.cls.tolist()
62
  # cls = set()
 
64
  # cls.add(model.names[int(cno)])
65
 
66
  # count_result = results.pandas().xyxy[0].value_counts('name')
67
+ return render
68
  # results = model.predict(image, imgsz=image_size, return_outputs=True)
69
  # results = model.predict(image)
70
  # object_prediction_list = []
 
94
  # output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
95
  # return output_image['image']
96
  # render = render_result(model=model, image=image, result=results[0])
97
+ def count_objects(predictions, target_classes):
98
+ object_counts = {x: 0 for x in target_classes}
99
+ for prediction in predictions:
100
+ for c in prediction.boxes.cls:
101
+ c = int(c)
102
+ if c in target_classes:
103
+ object_counts[c] += 1
104
+ elif c not in target_classes:
105
+ object_counts[c] = 1
106
+
107
+ present_objects = object_counts.copy()
108
+
109
+ for i in object_counts:
110
+ if object_counts[i] < 1:
111
+ present_objects.pop(i)
112
+
113
+ return present_objects
114
 
115
 
116
 
 
130
  title = "Tất cả do anh Đạt"
131
 
132
  interface_image = gr.Interface(
133
+ fn=yolov8_img_inference, count_objects
134
  inputs=inputs_image,
135
  outputs=[gr.Image(type="pil"),gr.Textbox(show_label=False)],
136
  title=title,