【发布时间】:2021-05-22 09:39:08
【问题描述】:
我从带有this 模型的视频中检测到对象。该模型检测三类:自行车、汽车和人。我只想要汽车和人,这就是我得到的,直到图片中有自行车。然后我收到一个错误IndexError: list out of range。
这是我的代码:
CLASSES = ["bicycle", "car", "person"]
for i in np.arange(0, detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > 0.4:
idx = int(detections[0, 0, i, 1])
if CLASSES[idx] == "person" or CLASSES[idx] == "car":
print("CLASSES[idx]: ", CLASSES[idx])
错误指向以下行:if CLASSES[idx] == "person" or CLASSES[idx] == "car":。我已经尝试像这样检查其他索引(自行车):
if CLASSES[idx] == "person" or CLASSES[idx] == "car":
print("CLASSES[idx]: ", CLASSES[idx])
else:
print("Not a car/person")
continue
错误仍然相同,并且从未执行过 else。欢迎任何建议这里有什么问题。
编辑。我做了一些记录,发现索引有时是 3,这就是脚本失败的原因。模型文件说:
The net outputs blob with shape: [1, 1, N, 7], where N is the number of detected bounding boxes. Each detection has the format [image_id, label, conf, x_min, y_min, x_max, y_max], where:
image_id - ID of the image in the batch
label - predicted class ID
conf - confidence for the predicted class
(x_min, y_min) - coordinates of the top left bounding box corner
(x_max, y_max) - coordinates of the bottom right bounding box corner.
那么我是否以错误的方式进行检测?
这就是我获得检测结果的方式:
net = cv2.dnn.readNet(
"models/person-vehicle-bike-detection-crossroad-0078.xml",
"models/person-vehicle-bike-detection-crossroad-0078.bin")
detections = net.forward()
【问题讨论】:
标签: python numpy for-loop index-error openvino