linhcuem commited on
Commit
5627083
1 Parent(s): de6914b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -56,10 +56,20 @@ 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
 
60
- for r in results:
61
- for c in r.boxes.cls:
62
- count = print(names[int(c)])
 
 
63
 
64
  # clist= results[0].boxes.cls.tolist()
65
  # cls = set()
@@ -67,7 +77,7 @@ def yolov8_img_inference(
67
  # cls.add(model.names[int(cno)])
68
 
69
  # count_result = results.pandas().xyxy[0].value_counts('name')
70
- return render, count
71
  # results = model.predict(image, imgsz=image_size, return_outputs=True)
72
  # results = model.predict(image)
73
  # object_prediction_list = []
 
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
  # 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 = []