ShayanPersonal/checkered-cnn

When trying to use this on any other model, error arises:

JDvorak opened this issue · 3 comments

RuntimeError: expected stride to be a single integer value or a list of 2 values to match the convolution dimensions, but got stride=[1, 2, 2]

This arises from an error in nn/modules/conv.py inside of pytorch, and is generated by your code at line 122, in checkered_forward.

Any advice?

I see that error when the dimensions of my input is wrong.

Are you feeding your network 5D inputs? The input to conv should be (batch_size, channels, submaps, height, width). If you're using your own network you need to do something like x = x.unsqueeze(2) before passing it through checkered layers.

If you want to convert it back to a regular feature map afterwards for processing by standard layers, you can do something like x = torch.mean(x, 2).

When applying convert_to_checkered on your own CNN you need to modify the forward pass to add in the submap dimension. I just realized I didn't explain that in my readme, sorry about that! I updated the readme with instructions on how to apply this on your own networks. One gotcha is calls to torch.nn.functional which can't be detected by the conversion script.

Also, the conversion script only supports the most common layers and may break if you're using a really custom architecture that it hasn't been tested to handle. In that case you'll have to go through your architecture's code and manually replace your layers with checkered layers, or you can edit the conversion script to handle your unique cases. See CheckeredCNN underneath demo_mnist.py for an example of what building a checkered CNN from scratch looks like.

I added a warning for when your model includes layers that aren't handled by the conversion script, so update your repository.

Thank you. This answered my question, and it works fantastic.