简体   繁体   中英

values in torch.nn.conv2d and torch.nn.Linear

I am confiused how to get the out_channels in torch.nn.Conv2d and the in_features, out_features in torch.nn.Linear .
For example I have a non-color 28*28 image input. the in_channels = 1,kernel_size=5,padding=2 how can I figure the out_channels .
After the convolutional, I want to make a linear layer. How do I figure the values of in_features, out_features ?

The choice of out_channels is up to you, it's the number of filters you want your convolutional layer to compute. The higher this number is, the heavier the layer will be, but on the other hand the more features it will be able to learn (theoretically).

After going through the convolution (assuming out_channels = C ), your data will have shape (C, 28, 28) . In other words, one sample contains 28*28*C numbers / dimensions. It is this number that you need to input as in_features for the following linear layer. Then again, out_features is up to you.

I strongly suggest that you read and learn about neural networks (and their typical convolutional and linear layers) before attempting to use them to make magic happen. Without the required knowledge about them, you will at best be able to produce results that you don't really understand, and at worst issues that you don't know how to fix. It takes time to learn, but it really is worth it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM