I tried your UNet demo 43, with other input size like this:
x = torch.randn(1, 3, 240, 180)
y = torch.randint(0, nb_classes, (1, 240, 180))

and got

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 45 and 44 in dimension 3

And I found online 176 tips you can resize or tweak UNet.
Looks like no way around.
That way it has lot of sense to create UNets that examine the input and output size and create the architecture dynamically based on that.