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

Reshape issue while running net.forward() #832

Open
ArushikaBansal opened this issue Jun 17, 2023 · 3 comments
Open

Reshape issue while running net.forward() #832

ArushikaBansal opened this issue Jun 17, 2023 · 3 comments

Comments

@ArushikaBansal
Copy link

ArushikaBansal commented Jun 17, 2023

While running notebook 'multi-person-openpose.ipynb' encountered an issue in the code

t = time.time()
net = cv2.dnn.readNetFromCaffe(protoFile, weightfile)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)

if device == "cpu":
net.setPreferableBackend(cv2.dnn.DNN_TARGET_CPU)
print("Using CPU device")
elif device == "gpu":
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
print("Using GPU device")

Fix the input Height and get the width according to the Aspect Ratio
inHeight = 368
inWidth = int((inHeight/frameHeight)*frameWidth)

inpBlob = cv2.dnn.blobFromImage(image1, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)

net.setInput(inpBlob)
output = net.forward()
print("Time Taken = {}".format(time.time() - t))


error Traceback (most recent call last)
in <cell line: 23>()
21 # inpBlob = np.squeeze(inpBlob,0)
22 net.setInput(inpBlob)
---> 23 output = net.forward()
24 # print("Time Taken = {}".format(time.time() - t))

error: OpenCV(4.7.0) /io/opencv/modules/core/src/matrix.cpp:1240: error: (-209:Sizes of input arguments do not match) Requested and source matrices have different count of elements in function 'reshape'

Please help me to solve this issue. Thanks in advance :)

@brmarkus
Copy link

Looks like the code doesn't match to the model (anylonger).
Which version of the code/notebook/repo and which version of the model do you use? Do you use the original model of the sample, or used your own retrieved one?
Can you add a few print-log-messages of the provided input-shape and of the expected input-shape? You might check the model via a model-viewer like "Netron" and check the expected input-shape.

@ArushikaBansal
Copy link
Author

I have simply run the notebook below:
https://github.com/spmallick/learnopencv/blob/master/OpenPose-Multi-Person/multi-person-openpose.ipynb
with protoFile and weightFile as given. I kept the input also the same.
The Openpose vesion is 4.7.0

@brmarkus
Copy link

brmarkus commented Jun 17, 2023

Now I tried it under MS-Win10 in a Python virt-env using thhe Jupyter notebook as well.
I got a cv2.error: Unknown C++ exception with the instruction net.setInput(inpBlob).

Via Google search I found e.g. this pointer: "https://stackoverflow.com/questions/75334101/layeroutputs-net-forwardoutput-layers-names-cv2-error-unknown-c-exception"

Yes, I had manually installed pip3 install opencv-python, and now manually installed pip3 install opencv-python==4.6.0.66.

With this version I got the Jupyter notebook to run successfully:

image

image

image

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