[Attention-OCR memorizing patterns]
Hello,
First of all I want to thank you for this awesome repository. I tried to run attention-ocr on my dataset which contains images with dates in this format: 30/12/18. After 48k steps on 150k training dataset with a batch size of 32, even if the accuracy on the training dataset is almost 90%, on the qa the accuracy is below 5 percent. So, the problem is that the model is learning patterns and it cannot generalize. More exactly in the training data was images with dates only from 2017 and 2018, and the qa there was only dates from 2019. The datasets was created specially to verify this specific problem. So the question is: Is there something that can be done with the loss function or with other component in order to avoid this problem? Thank you a lot!
The answers for all neural networks: More data, More regularization, Early stopping IE, stop when your test set achieves the max score.
Neural networks with enough neurons can memorize any dataset. So when training most networks they will eventually hit 100% accuracy on the training set and something very low on the test set. Usually the test accuracy goes up over time then back down. You need to stop training it when you see that it is memorizing more than learning general concepts. There are also a ton of little things that could be wrong with how your dataset, training, or model.
But is not memorizing the dataset. is memorizing the fact that every date ends with an 7 or an 8. If I make inference on a different dataset than the training one, but with dates from the same years, the model preserves it's accuracy. The problem is coming from the RNN, I suppose. It's there a way to perform OCR without RNNs, I mean only with convolutional layers and an encoder-decoder mechanism?
I suspect that there is a big difference between your training data and your holdout data. I'm pretty sure the model has no concept of the filename unless you are specifically feeding that information to it.
There are many generalization techniques out there, but neural networks don't do well switching between different types of inputs even if the changes are subtle.
I would find a way to split up your data differently so that you have some 2019 data in your training dataset as well.
There is no easy way to switch out an rnn to a cnn in the models here. I'm pretty confident that doing so would not solve your problem either.
I think I did not express myself quite well. The images from the dataset contains "dates", like a sequence of numbers e.g.

It is nothing about the filenames.
So, it is obviously that a dataset containing dates from 2019 will do it, but I want to solve the problem assuming that I do not have data from 2019 and to make the network to generalize more, because after all, the model sees in the images all the characters from 0 to 9 in order to learn from them so this is not a problem. The problem is the sequence of this characters which is more or less a pattern and the RNN is learning it, knowing that every time there will be a 7 or an 8 at the end of the sequence even if is not.
I suggest you CREATE yourself the data required for the NN to learn. Try to develop a model to read your old years images, then use that model to generate a new dataset which contain 19. Maybe this is not easy but it would solve your problem. At worst case you may generate the dataset using some font that is similar to handwritten or use other online datasets.
Hi There, We are checking to see if you still need help on this, as this seems to be an old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.