【问题标题】:Darknet YoloV4 empty predictionDarknet YoloV4 空预测
【发布时间】:2021-05-30 01:07:34
【问题描述】:

我正在尝试使用 YoloV4 和 Darknet 在 python 中检测图像中的对象。 问题是它没有检测到图像中的任何对象。这是我的代码:

configPath = "./cfg/yolov4.cfg"                                 
weightPath = "./yolov4.weights"                                 
metaPath = "./cfg/coco.data"

netMain = darknet.load_net_custom(configPath.encode("ascii"), weightPath.encode("ascii"), 0, 1)
metaMain = darknet.load_meta(metaPath.encode("ascii"))
altNames = None
try:
    with open(metaPath) as metaFH:
        metaContents = metaFH.read()
        import re
        match = re.search("names *= *(.*)$", metaContents, re.IGNORECASE | re.MULTILINE)
        if match:
            result = match.group(1)
        else:
            result = None
        try:
            if os.path.exists(result):
                with open(result) as namesFH:
                     namesList = namesFH.read().strip().split("\n")
                     altNames = [x.strip() for x in namesList]
        except TypeError:
            pass
except Exception:
    pass

frame_width = darknet.network_width(netMain)
frame_height = darknet.network_height(netMain)

frame = cv2.imread("b.jpg")

darknet_image = darknet.make_image(frame_width, frame_height, 3)
darknet.copy_image_from_bytes(darknet_image, frame.tobytes())
detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.25)
print(detections) #returns []

程序打印“[]”。图片(“b.jpg”)为 764x756。

【问题讨论】:

    标签: python yolo darknet yolov4


    【解决方案1】:

    您需要将图像调整为适当的大小。

    frame = cv2.resize(cv2.imread("b.jpg"), (frame_width, frame_height))

    确保图片中包含您要查找的对象。

    在使用python脚本之前,使用darknet test确保模型可以检测到物体。

    【讨论】:

    • 我用 cmd 的暗网测试对图像进行了测试,它识别出两个人,所以图像有对象。我也尝试使用您的代码调整图像大小,但这次什么也没发生,它永远不会从 darknet.detect_image() 中返回
    • 在这种情况下,您可以尝试使用来自 AlexeyAB 存储库的更新 API 吗?或者,您可以尝试使用此模型服务器github.com/zabir-nabil/darknet-fastapi-modelserver
    • 更新的 API 是什么意思?我正在使用 AlexeyAB 的暗网(我自己编译),我尝试了 cmd 命令“darknet.exe 检测器测试 cfg/coco.data cfg/yolov4.cfg yolov4.weights”,它工作正常。
    猜你喜欢
    • 2021-12-04
    • 2021-12-09
    • 2021-05-05
    • 2021-10-08
    • 2021-07-21
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多