I am facing the similar issues while calculating cross-entropy loss. Here is my sample code:
loss_fn = nn.CrossEntropyLoss()
for epoch in range(100):
    model.train()
    train_acc = 0.0
    train_loss = 0.0
    for images in os.listdir(current_path):
        I = Image.open(images)
        x = image_transform(I).float().reshape([1,3,224,224])
        output = model(x)
        loss = loss_fn(output,labels)
        loss.backward()
        optimizer.step()
        train_loss += loss.cpu()
        _, prediction = torch.max(outputs.data, 1)

My labels are as follows:
labels.shape
torch.tensor([16])
output.shape
torch.tensor([1,16])

As per the doccumentation of cross-entropy loss, input and target must be tensor of size (N,C) and (N) .I have tried by resizing it but failed. Can you suggest me any solution. Thanks.