【发布时间】:2021-04-11 13:34:12
【问题描述】:
我是神经网络的新手。我正在尝试使用 opencv 进行对象检测。我正在使用 yolov3 预训练模型进行对象检测。这段代码在我的旧笔记本电脑上运行良好,但最近我开始使用新笔记本电脑(i5 9th gen)。我的旧代码(opencv)不起作用。 outs=net.forward(output_layers) 返回 nan 值,我使用的是 opencv-python 4.5.0 版本。我无法理解出了什么问题。我正在添加代码图片(spyder)code and output 和我的环境中的包列表package in my environment #--------- 我的代码 #---------
import cv2
import numpy as np
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
classes = []
with open("coco.names", "r") as f:
classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in
net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))
img = cv2.imread("spiritualeye.jpg")
img = cv2.resize(img, None, fx=0.4, fy=0.4)
blob=cv2.dnn.blobFromImage(img,0.00392, (416, 416), (0, 0, 0), True,
crop=False)
net.setInput(blob)
outs=net.forward(output_layers)
print(outs)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#-----------------------
【问题讨论】:
标签: python opencv conv-neural-network