The shapes are alright.
If the target only contains values 0 and 1, it should work:
criterion = nn.CrossEntropyLoss()
output = torch.randn(1, 2, 256, 256)
target = torch.randint(0, 2, (1, 256, 256))
loss = criterion(output ,target)