Cannot reshape tensor to desired shape

I am creating a tensor using torch.frombuffer(). The buffer contains image data. When i am trying to reshape the tensor to (H,W,C) I am getting the following error:

Error in processing frame: shape ‘[640, 640, 3]’ is invalid for input of size 1310720.

Could this be due to stride bytes?

Maybe because 640 * 640 * 3 is not equal to 1310720?

I am receiving the buffer from a gstreamer pipeline. And i have reshaped the image to 640x640 inside the pipeline before creating the tensor.

Can you confirm the frame size from gstreamer is really 640x640? Is the size of your buffer fixed or is it guaranteed to the the exact same size as the number of bytes in a single frame? Because 1310720 bytes is more than a single frame. It might be that you are receiving extra bytes that you need to keep track of and only take 640 * 640 * 3 (1228800) if they are available. A code snippet would also help.