Thanks @ptrblck.
I tried another way, I just added another linear layer like this
self.linear2 = nn.Linear(in_features=100,out_features=128*30*30) and in the forward function, I used
x = x.view(x.size(0),128,30,30)) and kept the rest of the code same. When I print the output after every layer in the forward method, I am getting the desired shape. But when I start training, I am getting the following error
RuntimeError: shape '[8, 115200]' is invalid for input of size 2113536 despite resizing all images to (128,128) in my dataloader.
Could you please have a look at my code 21 (Google Colab notebook).