Hi,
You can unflatten after the fully connected layer:
original_size = input.size()
flat_input = input.view(original_size[0], -1)
flat_ouput = linear(flat_input)
output = flat_output.view(original_size)