I am facing problems with the argparse library.
I have the encodings.pickle file and I am following the below code to recognize the actors but it seems to load the embeddings is not working.
Here is the code:
ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
help="face detection model to use: either `hog` or `cnn`")
ap.add_argument("-fnn", "--fast-nn", action="store_true")
args = parser.parse_args('')
print(args)
# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())
Source code can be found here.
You are getting this error because the parse_args() method returns a Namespace containing the parsed arguments.
When printing the result of that method, you will see the created namespace: Namespace(encodings='encoding', image='image', detection_method='cnn', fast_nn=False)
In order to access arguments, you should use dot notation (i.e. args.encodings or args.image)
Amended code:
ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
help="face detection model to use: either `hog` or `cnn`")
ap.add_argument("-fnn", "--fast-nn", action="store_true")
args = parser.parse_args()
print(args)
# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args.encodings, "rb").read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With