Based on your description I assume you are working on a multi-class segmentation use case, i.e. each pixel belongs to one of the 7 classes.
In that case, the target should not contain the channel dimension (number of classes), but instead have the shape [batch_size, height, width] and contain values in the range [0, nb_classes].
Here is a small dummy code using your shapes:
nb_classes = 7
batch_size, height, width = 32, 224, 224

output = torch.randn(batch_size, nb_classes, height, width, requires_grad=True)
target = torch.randint(0, nb_classes, (batch_size, height, width))

criterion = nn.CrossEntropyLoss()

loss = criterion(output, target)
loss.backward()