These files can be downloaded from the Internet, or created and trained manually.

For Caffe:

  • res10_300x300_ssd_iter_140000_fp16.caffemodel

  • deploy.prototxt

For Tensorflow:

  • opencv_face_detector_uint8.pb

  • opencv_face_detector.pbtxt

In [4]:
# load our serialized model from disk
print("[INFO] loading model...")

if DNN == "CAFFE":
    modelFile = "res10_300x300_ssd_iter_140000_fp16.caffemodel"
    configFile= "deploy.prototxt"
    
    # Here we need to read our pre-trained neural net created using Caffe
    net = cv2.dnn.readNetFromCaffe(configFile, modelFile)
else:
    modelFile = "opencv_face_detector_uint8.pb"
    configFile= "opencv_face_detector.pbtxt"
    
    # Here we need to read our pre-trained neural net created using Tensorflow
    net = cv2.dnn.readNetFromTensorflow(modelFile, configFile)
    
print("[INFO] model loaded.")
[INFO] loading model...
[INFO] model loaded.