Tehreem:

        x = x.view(-1,512)


a better way to write this since it flatten the output of conv layer is
shape = torch.prod(torch.tensor(x.shape[1:])).item()
x =  x.view(-1, shape)

Also



 Tehreem:

    self.fc1 = nn.Linear(128, 1024, bias=False)


should be
self.fc1 = nn.Linear(Number of Flattened Features from last layer , 1024,...)

Further, read this post for better understanding.

  
    
    
    Flatten layer of PyTorch build by sequential container 
  
  
    I am trying to build a cnn by sequential container of PyTorch, my problem is I cannot figure out how to flatten the layer. 
main = nn.Sequential()
self._conv_block(main, 'conv_0', 3, 6, 5)
main.add_module('max_pool_0_2_2', nn.MaxPool2d(2,2))
self._conv_block(main, 'conv_1', 6, 16, 3)
main.add_module('max_pool_1_2_2', nn.MaxPool2d(2,2)) 
main.add_module('flatten', make_it_flatten)

What should I put in the “make_it_flatten”? I tried to flatten the main but it do not work, main do not exist someth…