Input Shape of Deep learning model

Viewed 107

I have created deep learning models in different input shapes. For Testing , I am resizing the images according to the model's input shape manually I need to resize the image with input shape of the deep model Any Command to find the input shape of the model in PYTORCH

model = torch.load(config.MODEL_PATH).to(config.DEVICE)
im = cv2.resize(im, (INPUT_IMAGE_HEIGHT,INPUT_IMAGE_HEIGHT))

How can I find the INPUT_IMAGE_HEIGHT,INPUT_IMAGE_HEIGHT from model

Thank You

1 Answers

This is a tricky question because your input size will can depend on several components of your model. The short answer is you can't.


Concerning the number of channels in your input tensor, you can infer this solely based on the first convolutional layer. Assuming your model is a two dimensional convolutional network, then you can get the input channel number based on :

for child in model.modules():
    if type(child).__name__ == 'Conv2d':
        print(child.weight.size(1))
        break

Now for the input size, as I said you may not be able to infer this information at all. Indeed some convolutional networks, such as classification networks, may require specific dimensions such that the bottleneck can be flattened and fed into a fully-connected network. This is not always true though, networks that use some sort of pulling operation (average, or maximum pulling) will alleviate the need to provide fixed input shapes. Other networks such as dense prediction networks may not need to get a specific shape as the input, given the symmetry between input and output...

This all depends on the network's design and as such, I'm afraid there is no definitive answer to your question.

Related