It should probably be 50*50*32.
You could add a print statement just before flattening x:
out = self.layer2(out)
print(out.shape)

Passing an input through the model you will get the right shape to use for your flattening.