output = torch.rand(2,4,4,2,requires_grad=True)

    target = torch.tensor([[[[0, 1],
              [1, 0],
              [1, 0],
              [0, 1]],

             [[1, 0],
              [0, 1],
              [0, 1],
              [1, 0]],

             [[0, 1],
              [0, 1],
              [1, 0],
              [1, 0]],

             [[0, 1],
              [1, 0],
              [0, 1],
              [0, 1]]],

            [[[0, 1],
              [0, 1],
              [1, 0],
              [0, 1]],

             [[0, 1],
              [0, 1],
              [0, 1],
              [1, 0]],

             [[1, 0],
              [1, 0],
              [1, 0],
              [0, 1]],

             [[1, 0],
              [1, 0],
              [0, 1],
              [0, 1]]]])

    output = output.view(-1,4)
    target = target.view(-1,4).argmax(1)
    loss = torch.nn.CrossEntropyLoss(reduction='none')
    my_loss = loss(output, target).view(-1,4,4)

I didn’t know of a more graceful way to produce random label. Would have been more appealing to eye if I did.