PyTorch and Convolutional Neural Networks
I have a image input 340px*340px and I want to classify it to 2 classes.
I want to create convolution neural network (PyTorch framework). I have a problem with input and output of layer.

class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        # 3 channels (RGB), kernel=5, but i don't understand why 6. 
        self.conv1 = nn.Conv2d(3, 6, 5)
        self.pool = nn.MaxPool2d(2, 2)
        #why 16?
        self.conv2 = nn.Conv2d(6, 16, 5)
        #why 107584 = 328*328
        self.fc1 = nn.Linear(107584, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 2)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = self.pool(F.relu(self.conv2(x)))
        # i dont understand this line
        x = x.view(x.size(0),  -1)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x


Is it network is correct?


  # 3 channels (RGB), kernel=5, but i don't understand why 6. 


The second parameter of Conv2d is out_channels. In a convolutional layer you can arbitrarily define a number of out channels. So it's set to 6 because someone set it to 6. 


  # why 16?


Same as above.


  #why 107584 = 328*328


and


  \ # i dont understand this line


Tensor.view() returns a new tensor with the same data as the self tensor but of a different size.
x = x.view(x.size(0),  -1): -1 means "infer from other dimensions" so, you are forcing the Tensor to be [1, 15*164*164] => [1, 403440]. 

403440 is also the correct value for self.fc1 = nn.Linear(107584, 120), instead of 107584.
