[英]Object Detection using YOLO : get count of each detected object
I am using YOLO to identify objects which is working fine however, I want to get count of the vehicles identified and to apply some calc_pollution
further.我正在使用 YOLO 来识别工作正常的对象,但是,我想获得识别的车辆的数量并进一步应用一些calc_pollution
。 I am using below code however, I am getting error: TypeError: list indices must be integers or slices, not tuple
for the line: L = [labels.get(value) for index,value in enumerate(v_labels[0]) if v_scores[0,index] > 0.1]
但是,我正在使用以下代码,但出现错误: TypeError: list indices must be integers or slices, not tuple
: L = [labels.get(value) for index,value in enumerate(v_labels[0]) if v_scores[0,index] > 0.1]
# correct the sizes of the bounding boxes for the shape of the image
correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)
# suppress non-maximal boxes
do_nms(boxes, 0.5)
# define the labels
labels = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck",
"boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe"]
# get the details of the detected objects
v_boxes, v_labels, v_scores = get_boxes(boxes, labels, class_threshold)
# summarize what we found
for i in range(len(v_boxes)):
print(v_labels[i], v_scores[i])
# draw what we found
draw_boxes(photo_filename, v_boxes, v_labels, v_scores)
# Filtering results
L = [labels.get(value) for index,value in enumerate(v_labels[0]) if v_scores[0,index] > 0.1]
M=[]
vehicles=['car','bus','truck','motorcycle','auto-rickshaw']
for i in L:
if i['name']in vehicles:
M.append(i['name'])
S=set(M)
text=''
car=motorcycle=truck=bus=auto_rickshaw=0
for i in S:
if i == 'car': car += M.count(i)
if i == 'motorcycle': motorcycle += M.count(i)
if i == 'truck': truck += M.count(i)
if i == 'bus': bus += M.count(i)
if i == 'auto-rickshaw' : auto_rickshaw += M.count(i)
text+=str(i +' : '+ str(M.count(i))+"\t" )
print('Vehicles Identified -',text)
calc_pollution(car, motorcycle, truck, bus, auto_rickshaw)
Any help would be appreciated.任何帮助,将不胜感激。
Is v_scores a list of nested lists? v_scores 是嵌套列表的列表吗? Is so, you would need to change this part v_scores[0,index]
to something like v_scores[0][index]
是这样,您需要将这部分v_scores[0,index]
更改为类似v_scores[0][index]
If that doesn't work, please share more information about the contents of v_boxes, v_labels, and v_scores.如果这不起作用,请分享有关 v_boxes、v_labels 和 v_scores 内容的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.