Reputation: 5078
Why do I get the error `AttributeError: module 'cv2' has no attribute 'dnn_DetectionModel' when I try to run this code:
# 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)
Error
---------------------------------------------------------------------------
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'
I have upgraded my open cv by typing this in the terminal: pip install opencv-python --upgrade
and this was the result
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
This is the only cv2.dnn I have:
Upvotes: 3
Views: 10002
Reputation: 1
use
net = cv2.dnn.readNetFromTensorflow(weightsPath,configPath)
instead of
net = cv2.dnn_DetectionModel(weightsPath, configPath)
Upvotes: 0
Reputation: 21
You can also try updating the opencv module once. It worked in my case, after I updated my opencv module to opencv 4. Try running this command and see if it works:
pip install --upgrade opencv-python
Upvotes: 2
Reputation: 6829
You need to install OpenCV_contrib to use the DNN functionality which can be done with the link below I would suggest using the CMAKE gui
Link with the steps to build opencv_contrib
Upvotes: 2