Problems in running Opencv with yolo : “AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU"

459 views Asked by At

When I try to run the following code below for object detection through yolo3 on jupyter notebook:

classfile = "coco.names"
classes = []
wht = 320

with open(classfile,"rt") as f:
classname = f.read().rstrip("\n").split("\n")

modelconfiguration = "yolov3.cfg"
modelweight = "yolov3.weights"

net = cv2.dnn.readNetFromDarknet(modelconfiguration,modelweight)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGEGT_CPU)

at the last row which is net.setPreferableTarget(cv2.dnn.DNN_TARGEGT_CPU) causes the error below.

    AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU'

I have already tried upgrading opencv but this did not resolve the issue.

1

There are 1 answers

0
Zock77 On BEST ANSWER

I believe it is simply a typo. Try replacing that last line with:

net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)

The typo of course being spelling TARGET as TARGEGT

Here is a list of Opencv DNN targets: https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga709af7692ba29788182cf573531b0ff5