使用opencv的微小yolo v4无法进行检测



我已经在谷歌colab上的自定义数据集上训练了yolo-tiny-v4,检测效果很好。然后,我尝试在opencv的dnn模块的帮助下,在其他colab项目中加载yolo-tiny-v4,没有出现错误,但检测失败(没有检测到对象,检测的输出是Nan的向量(。

[array([[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
...,
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.]], dtype=float32),
array([[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
...,
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.],
[nan, nan, nan, nan, nan,  0.]], dtype=float32)]

我在colab上使用OpenCV 4.5.1版和Python 3.7版。知道吗?

这是代码

#Load YOLO
net = cv2.dnn.readNetFromDarknet("/content/custom-yolov4-tiny-detector.cfg","/content/custom-yolov4- 
tiny-detector_last.weights")
classes = []  
with open("obj.names","r") as f:
classes = [line.strip() for line in f.readlines()]
net.getLayerNames()
layer_names = net.getLayerNames()
outputlayers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
#loading image
img = cv2.imread("/content/1.png")
#img = cv2.resize(img,None,fx=0.4,fy=0.3)
height,width,channels = img.shape
cv2_imshow(img)
blob = cv2.dnn.blobFromImage(img,0.00392,(416,416),(0,0,0),True,crop=False)
net.setInput(blob)
outs = net.forward(outputlayers)
outs

作为一个初学者,我忘记在colab 中安装暗网

相关内容

  • 没有找到相关文章

最新更新