Problems in running Opencv with yolo : “AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU"
Problems in running Opencv with yolo : “AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU"
当我尝试 运行 下面的代码通过 jupyter notebook 上的 yolo3 进行对象检测时:
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)
最后一行 net.setPreferableTarget(cv2.dnn.DNN_TARGEGT_CPU)
导致以下错误。
AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU'
我已经尝试升级 opencv 但这并没有解决问题。
我认为这只是一个错字。尝试将最后一行替换为:
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
当然是拼写错误 TARGET 为 TARGEGT
这里是 Opencv DNN 目标列表:https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga709af7692ba29788182cf573531b0ff5
当我尝试 运行 下面的代码通过 jupyter notebook 上的 yolo3 进行对象检测时:
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)
最后一行 net.setPreferableTarget(cv2.dnn.DNN_TARGEGT_CPU)
导致以下错误。
AttributeError: module 'cv2.dnn' has no attribute 'DNN_TARGEGT_CPU'
我已经尝试升级 opencv 但这并没有解决问题。
我认为这只是一个错字。尝试将最后一行替换为:
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
当然是拼写错误 TARGET 为 TARGEGT
这里是 Opencv DNN 目标列表:https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga709af7692ba29788182cf573531b0ff5