NOTE: Each image in the dataset has size 28x28, so the data has size 28x28x32 (since batch_size is 32); kernelsize = 3 in the convolutional layer, and default stride = 1. To calculate output size of the convolution layer we use this formula: convolutionOutputSize = 1+ (inputSize - kernelSize)/stride = 1+ (28 - kernelSize)/stride The final output of the convolution layer, and therefore the input to the 1st linear layer will then have the following size: convolutionOutputSize x convolutionOutputSize x 32 2 Linear layers. The last linear layer is already defined. For the forward propogation function use F.relu as the activation function for the convolution layer and the first linear layer. The last linear layer and the activation function for it (softmax) are already written. CODE: class MyModel(nn.Module): def__init__(self): super(MyModel, self).__init__() # DEFINE CONVOLUTION LAYER HERE, CALL IT self.conv1 *** #self.conv1 = **complete this line** # DEFINE LINEAR LAYER 1 HERE, CALL IT self.d1 *** #self.d1 = **complete this line** self.d2 = nn.Linear(128,10) defforward(self, x): ## *** WRITE CONVOLUTION LAYER HERE *** x = x.flatten(start_dim = 1) # we use a flatten between the convolution and linear layers ## *** WRITE FIRST LINEAR LAYER HERE *** logits = self.d2(x) #10 class score out = F.softmax(logits, dim=1) return out
NOTE: Each image in the dataset has size 28x28, so the data has size 28x28x32 (since batch_size is 32); kernelsize = 3 in the convolutional layer, and default stride = 1. To calculate output size of the convolution layer we use this formula:
convolutionOutputSize = 1+ (inputSize - kernelSize)/stride = 1+ (28 - kernelSize)/stride
The final output of the convolution layer, and therefore the input to the 1st linear layer will then have the following size: convolutionOutputSize x convolutionOutputSize x 32
-
2 Linear layers. The last linear layer is already defined.
-
For the forward propogation function use F.relu as the activation function for the convolution layer and the first linear layer. The last linear layer and the activation function for it (softmax) are already written.
CODE:
Step by step
Solved in 4 steps with 1 images