Is my custom loss function correct? (Pytorch)
I want to do word recognition using a CNN + Classifier, where the input is an image and the output a matrice 10x37. 10 is the maximum number of characters in a word and 37 is the number of letters in my example.

I wrote a custom loss function for this model but I'm not sure if it's correct since I can't get above 80% Test Accuracy.

I'm using Pytorch

class CustomLoss(nn.Module):
    def __init__(self):
        super().__init__()
        self.nllloss = nn.NLLLoss()

    def forward(self, output, labels):
        loss = 0
        for i in range(labels.shape[1]):
            loss += self.nllloss(output[:, i, :], labels[:, i])
        loss /= labels.shape[1]
        return loss


Infos:

output.shape = (batch_size, 10, 37)

labels.shape = (batch_size, 10)

Is the loss function correct? 
And what my classification problem is called (Multiple Multi class classification) ?

The loss function is correct.

The problem was in the file containing my training data. It was not correctly created. In fact, I flipped the dimensions in the images (width and height) so the result from my training set was indecipherable for my CNN.

Now that I have solved the problem, I have reached 99.8% test accuracy.
