modAL icon indicating copy to clipboard operation
modAL copied to clipboard

Modifying pytorch_integration.py to work with different-sized images?

Open michelewang opened this issue 4 years ago • 3 comments

Hi, I'm hoping to modify the code in pytorch_integration.py to work with images that are bigger than those in MNIST (i.e. bigger than 28x28). However, I keep running into errors because the tensors produced from my larger images do not match the dimensions of the CNN modAL provided as an example. Do you know how to adjust that neural network's parameters to accommodate different image sizes (e.g. 1024x1024 or 512x512)?

For context, this is the current CNN being used: image

michelewang avatar Feb 25 '21 17:02 michelewang

Hi!

The problem is going to be the first Linear layer. You have to calculate by the shape of self.convs(x), then multiply these together and use them in the definition of the Linear.

For example, if self.convs(x) gives an image of 128 x 128 x 64, you need to add nn.Linear(128*128*64, 128).

cosmic-cortex avatar Feb 28 '21 05:02 cosmic-cortex

@cosmic-cortex thank you so much!! I think that helped me figure out the dimensions of my neural net! Also as a follow up, is there a reason why you chose this neural network specifically for MNIST? I'm modifying it for my own uses (classifying damaged vs. undamaged buildings in satellite imagery) so was curious to understand why you chose to use this model.

Thank you!

michelewang avatar Mar 05 '21 22:03 michelewang

If I remember correctly, this exact network was used in the original Keras MNIST example, so I used it here for simplicity.

cosmic-cortex avatar Mar 06 '21 05:03 cosmic-cortex