Kalle:

self.input_size = input_size



kernel 5 with padding 0 will eat two rows and two columns from each side away in convolution, so after first conv2d your image dimension will be (H-4, W-4)
out_channels = 50
thus your nn.Linear input_features after flatten will be (H-4) * (W-4) * out_channels or  (input_size.shape[2] - 4) * (input_size.shape[3] - 4) * out_channels (==50)

also what @ptrblck is proposing is much easier. Fill input_channels with some arbitrary value, run dummy pass (I prefer torchinfo.summary in this case) and let torch to calculate these values for you in form of error)