微小的 yolo v4 与 opencv 的使用没有检测到

Tiny yolo v4 usage with opencv gives no detection

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

[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 中安装 darknet