detector = cv2.dnn.readNetFromCaffe(protoPath="D:/opencv-face-recognition/face_detection_model/deploy.prototxt", modelPath="D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel")
TypeError: readNetFromCaffe() missing required argument 'bufferProto' (pos 1)
你试试这个 cv2.dnn.readNetFromCaffe("D:/opencv-face-recognition/face_detection_model/deploy.prototxt", "D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel")
bufferProto: prototxt 这个文件没找着。就是 你 的 D:/opencv-face-recognition/face_detection_model/deploy.prototxt
Python 文件:
readNetFromCaffe(bufferProto[, bufferModel]) -> retval
. @brief Reads a network model stored in Caffe model in memory.
. * @param bufferProto buffer containing the content of the .prototxt file
. * @param bufferModel buffer containing the content of the .caffemodel file
. * @returns Net object.
因此,查文件在哪里,路径和文件名称合理吗?(名字对吗?有没有奇怪的字母)
文件检查加成:
import os
import cv2
# *.prototxt :模型构成
proto = 'D:/opencv-face-recognition/face_detection_model/deploy.prototxt'
# *.caffemodel:比重,画层
model = 'D:/opencv-face-recognition/face_detection_model/res10_300x300_ssd_iter_140000.caffemodel'
exist = os.path.exists(proto)
print('deploy.prototxt, 有吗? ', exist)
exist = os.path.exists(model)
print('res10_300x300_ssd_iter_140000.caffemodel, 有吗? ', exist)
# load model
print("[INFO] 启动 model...")
net = cv2.dnn.readNetFromCaffe(proto, model)
print(net)
这个更好,直接掐断:
def file_check(filename):
exist = os.path.exists(filename)
if not exist:
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), filename)
iris_file = 'D:/tensorflow/iris_training.csq'
file_check(iris_file)
print('file found: ', iris_file)