首页 > 解决方案 > AttributeError:模块“cv2”没有属性“dnn_DetectionModel”

问题描述

当我尝试运行此代码时,为什么会收到错误 `AttributeError: module 'cv2' has no attribute 'dnn_DetectionModel':

# get the weight configurations
 configPath = 
 '/Users/Rodne/MyComputerVision/Folder3/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt'
weightsPath = '/Users/Rodne/MyComputerVision/Folder3/frozen_inference_graph.pb'

# setting the bounding box
net = cv2.dnn_DetectionModel(weightsPath, configPath)
net.setInputSize(320, 320)

错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-355122b5b70e> in <module>()
      1 # setting the bounding box
----> 2 net = cv2.dnn_DetectionModel(weightsPath, configPath)
      3 net.setInputSize(320, 320)

AttributeError: module 'cv2' has no attribute 'dnn_DetectionModel'

我通过在终端中输入以下内容来升级我的开放式简历:pip install opencv-python --upgrade 这就是结果

Collecting opencv-python
  Downloading opencv_python-4.4.0.42-cp37-cp37m-win_amd64.whl (33.5 MB)
     |████████████████████████████████| 33.5 MB 54 kB/s
Requirement already satisfied, skipping upgrade: numpy>=1.14.5 in d:\anaconda\lib\site-packages (from opencv-python) (1.18.5)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.4.0.42

这是我唯一的 cv2.dnn: 在此处输入图像描述

标签: pythonopencv

解决方案


您也可以尝试更新一次 opencv 模块。在我将我的 opencv 模块更新为 opencv 4 之后,它在我的情况下有效。尝试运行此命令,看看它是否有效:

pip install --upgrade opencv-python

推荐阅读