Since your output and target shape do not match, but are broadcastable, you might get a wrong result.
Have a look at this example:
x = torch.arange(1, 5).view(2, 2)
y = torch.ones(2, 2)
loss = x - y
print(loss)

x = x.unsqueeze(1)
loss = x - y
print(loss)

While you would most likely expect the first result using your tensors, you might end up with the second one.
To resolve this issue, you could squeeze dim1 in your model output:
output = model(data)
output = output.squeeze(1)
loss = criterion(output, target)