Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing trained model directly using python opencv #10

Open
abhianand7 opened this issue Jul 21, 2020 · 1 comment
Open

Importing trained model directly using python opencv #10

abhianand7 opened this issue Jul 21, 2020 · 1 comment

Comments

@abhianand7
Copy link

abhianand7 commented Jul 21, 2020

Python: 3.6.9
opencv-python==4.2.0.34

Rather than trying to build this project with so little documentation, I decided to directly import the model in cv2 python but no success so far.

import cv2

proto_path = 'deploy.prototxt'
model_path = 'face_mask.caffemodel'

model = cv2.dnn.readNetFromCaffe(proto_path, model_path)

image_file = 'sample_images/0000.jpg'
img = cv2.imread(image_file)

image_blob = cv2.dnn.blobFromImage(img)

model.setInput(image_blob)

prediction = model.forward()

Error:
cv2.error: OpenCV(4.2.0) /io/opencv/modules/dnn/src/dnn.cpp:3084: error: (-215:Assertion failed) total(os[i]) > 0 in function 'getLayerShapesRecursively'

Did anyone had any success doing this or what else can be done to use the pre-trained model?

@ZPBerg
Copy link

ZPBerg commented Jan 13, 2021

Try
image_blob = cv2.dnn.blobFromImage(img, 1, (224, 224), (127.5, 127.5, 127.5))

deploy.prototxt indicates that the input should be a 224 x 224 image, and I got the 127.5 from here: https://github.com/didi/maskdetection/blob/master/lib/src/FaceMaskDetector.cpp#L72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants