What are you giving as input to your model ?
Beside the indentation error pointed out by tom above, your code is correct.
The input must be a 4 dimensional tensor alike (batch_size, channels, height, width)
For instance:
dummy_input = torch.randn(1, 1, 256, 256)
model = UNet()
output = model(dummy_input)
print(output.size()) # torch.Size([1, 1, 256, 256])

With the indentation fixed, I tried this and it worked.