“RuntimeError: Expected 4-dimensional input for 4-dimensional weight 32 3 3, but got 3-dimensional input of size [3, 224, 224] instead”?

As Usman Ali wrote in his comment, pytorch (and most other DL toolboxes) expects a batch of images as an input. Thus you need to call

output = model(data[None, ...])  

Inserting a singleton “batch” dimension to your input data.

Please also note that the model you are using might expect a different input size (3x229x229) and not 3x224x224.

Leave a Comment