【问题标题】:How to read YoloV3/YoloV4 in OpenCv to get the detections?如何在 OpenCv 中读取 YoloV3/YoloV4 以获取检测结果?
【发布时间】:2021-05-06 11:53:30
【问题描述】:

我有OpenCv 版本cv2.__version__ = '4.0.1',我正在尝试通过OpenCv 使用Yolov3 和YoloV4。我使用了来自AlexyAB's DarkNet git repo的权重和配置

Yolov4.config YoloV4.weights

类与coco.names/ classes.txt相同

我使用了许多不同的模块,但无法打开模型。

class DLFeaturesExtractor():
    '''
    Classs to Extract features from Image and plot on a Deep Learning Model
    '''
    def __init__(self,weight:str,config:str,cuda:bool=False,size:[tuple,list]=(416,416)):
        '''
        args:
            weight: path of weight file
            config: path to config file
            cuda: whether to use GPU and CudNN algos
            size: size of the input image
        '''
        self.weight = weight
        self.config = config
        net = cv2.dnn.readNet(self.weight,self.config)
        if cuda:
            net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
            net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA_FP16)
        self.model = cv2.dnn_DetectionModel(net)
        self.model.setInputParams(size=size,scale=1/255)

运行代码给我错误:

error: OpenCV(4.0.1) C:\ci\opencv-suite_1573470242804\work\modules\dnn\src\darknet\darknet_importer.cpp:207: error: (-212:Parsing error) Failed to parse NetParameter file: yolov4.cfg in function 'cv::dnn::dnn4_v20181221::readNetFromDarknet'

所以我使用了不同的东西:

cv2.dnn.readNetFromDarknet('yolov4.cfg','yolov4.weights',)

给我

error: OpenCV(4.0.1) C:\ci\opencv-suite_1573470242804\work\modules\dnn\src\darknet\darknet_io.cpp:552: error: (-212:Parsing error) Unsupported activation: mish in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'

我认为可能有参数交换,所以我也这样做了,同样的错误不断出现。

有人可以帮助我如何打开模型并从模型中进行推断吗?

我使用this gist 得到了这个想法,但似乎没有任何效果。

【问题讨论】:

  • github.com/AlexeyAB/darknet/wiki/YOLOv4-model-zoo 从这里获取模型和 cfg 并避免使用错误激活的版本,我认为您正在使用的 OpenCV 版本不支持该版本。
  • 刚刚使用opencv-contrib。为我工作。谢谢你的建议。另外,如果没有安装opencv-contrib,如何抛出错误?

标签: python opencv deep-learning computer-vision object-detection


【解决方案1】:

请注意,Opencv 4.2.0 和 4.3.0 不支持 Yolov4。 尝试下载master分支支持YoloV4的最新版本(根据KyloEntro

我个人已经将opencv-python升级到了4.5.3.56版本,再也没有报错了!

【讨论】:

    猜你喜欢
    • 2020-10-28
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    • 2012-04-10
    • 2016-11-25
    • 1970-01-01
    • 2021-07-21
    • 2017-07-31
    相关资源
    最近更新 更多