I tried to define a network in a more flexible way using nn.Sequential so that I can define its number of layers according to layernum:
nn.Sequential
layernum