You may get errors from the fact that you flatten your feature maps to pass it to a dense layer. This means that your architecture doesn’t allow arbitrary image sizes as inputs. You should do some debugging to get the dimensions right. For instance, try putting a print(x.size()) after your second convolution in your forward method. For it to work you should get a feature map of shape [5, 5, 10].