亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NameError:名稱'args'未定義?

NameError:名稱'args'未定義?

飲歌長嘯 2022-06-14 17:24:12
我正在嘗試https://www.pyimagesearch.com/2018/02/26/face-detection-with-opencv-and-deep-learning/?__s=zxeickrdq5xagzqfnz7z中給出的代碼import numpy as npimport argparseimport cv2ap = argparse.ArgumentParser()ap.add_argument("-i", "-C:/datasets/FACE/IMG_0375", required=True,help="path to input image")ap.add_argument("-p", "-C:/datasets/FACE/deploy.prototxt", required=True,help="path to Caffe 'deploy' prototxt file")ap.add_argument("-m", "-C:/datasets/FACE/res10_300x300_ssd_iter_140000", required=True,help="path to Caffe pre-trained model")# load our serialized model from diskprint("[INFO] loading model...")net = cv2.dnn.readNetFromCaffe(args["-p"], args["-m"])# load the input image and construct an input blob for the image# by resizing to a fixed 300x300 pixels and then normalizing itimage = cv2.imread(args["-i"])(h, w) = image.shape[:2]blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0, (300,    300), (104.0, 177.0, 123.0))# load our serialized model from diskprint("[INFO] loading model...")net = cv2.dnn.readNetFromCaffe(args["-p"], args["-m"])# load the input image and construct an input blob for the image# by resizing to a fixed 300x300 pixels and then normalizing itimage = cv2.imread(args["-i"])(h, w) = image.shape[:2]blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0,(300, 300), (104.0, 177.0, 123.0))以下是顯示的錯誤信息:[INFO] loading model...---------------------------------------------------------------------------NameError                                 Traceback (most recent call last)<ipython-input-9-f999c8fd8971> in <module>  1 # load our serialized model from disk  2 print("[INFO] loading model...")----> 3 net = cv2.dnn.readNetFromCaffe(args["-p"], args["-m"])  4   5 # load the input image and construct an input blob for the imageNameError: name 'args' is not defined正如我期望 ap = argparse.ArgumentParser() 允許我使用 args 一樣,為什么會出現此錯誤?
查看完整描述

2 回答

?
慕容森

TA貢獻1853條經驗 獲得超18個贊

請記住,您必須返回解析器。您已經獲得了價值,但您必須返回包含以下內容的對象:


ap = argparse.ArgumentParser()

ap.add_argument("-i", "-C:/datasets/FACE/IMG_0375", required=True,help="path to input image")

ap.add_argument("-p", "-C:/datasets/FACE/deploy.prototxt", required=True,help="path to Caffe 'deploy' prototxt file")

ap.add_argument("-m", "-C:/datasets/FACE/res10_300x300_ssd_iter_140000", required=True,help="path to Caffe pre-trained model")


#This line here :)

args = ap.parse_args()


查看完整回答
反對 回復 2022-06-14
?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

在這一行之后:

ap.add_argument("-m", "-C:/datasets/FACE/res10_300x300_ssd_iter_140000", required=True,help="path to Caffe pre-trained model")

您錯過了一行:

args = vars(ap.parse_args())


查看完整回答
反對 回復 2022-06-14
  • 2 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號