python - 如何在 OpenCv 中读取 YoloV3/YoloV4 以获取检测结果?
问题描述
我有OpenCv
版本cv2.__version__
= '4.0.1',我正在尝试使用 OpenCv 来使用 Yolov3 和 Yolov4。我使用了来自AlexyAB 的 DarkNet git repo 的权重和配置
我使用了许多不同的模块,但无法打开模型。
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'
我认为可能存在参数交换,所以我也这样做了,同样的错误不断出现。
有人可以帮助我如何打开模型并从模型中推断出来吗?
我用这个要点来理解这个想法,但似乎没有任何效果。
解决方案
请注意,Opencv 4.2.0 和 4.3.0 不支持 Yolov4。尝试下载 master 分支支持 YoloV4 中的最后一个版本(根据KyloEntro)
我个人已经将opencv-python升级到4.5.3.56版本,再也没有报错了!
推荐阅读
- api - 获取出现在 Schedule Revit API 上的链接元素
- vba - 我如何将特定列从一行复制到另一个工作表
- c++ - 使用 c++ 后将堆栈恢复到以前的状态
- java - 线程中的异步回调
- visual-studio-2017 - 无法编译 SharpSNMPLib - 项目中不存在目标“clean”
- python - 使用 ipaddress 库使用 while 循环问题查找 IP
- python - 通过 Spyder 连接 mysql
- google-app-engine - Bitbucket 管道:gcloud 崩溃 (UnicodeDecodeError)
- reactjs - 在 React 中调用类的 Webpack “不是函数”错误
- php - 对 PHP 对象数组进行排序,使相邻对象不共享特定的属性值