GabrielDornelles / pytorch-ocr

Simple Pytorch framework to train OCRs. Supports CRNNs, Attention, CTC and Cross Entropy Loss.
MIT License
72 stars 16 forks source link

Inference giving 45 characters output. #9

Closed AnishTadepalli closed 10 months ago

AnishTadepalli commented 10 months ago

Hi, I am training the model on captcha images, the model is getting upto 99.4% accuracy, and I can see the ground truth and prediction characters are same in length. But when I am using inference, I am getting 45 characters list as output. I have tried lot of things but still same type of output. Predictions: ['g', '8', '8', '8', '8', '8', '8', '8', 'n', 'f', 'w', 'w', '7', 'e', 'e', '8', 'w', 'x', 'w', 'x', 'w', 'b', 'f', 'f', 'f', 'w', '3', 'p', 'p', 'p', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', 'p', 'p', 'p', 'p', '7'] and the characters in the image are: 2b827 This is my config: defaults:

processing: device: cpu image_width: 180 image_height: 50

training: lr: 3e-4 batch_size: 8 num_workers: 4 num_epochs: 100

bools: DISPLAY_ONLY_WRONG_PREDICTIONS: true VIEW_INFERENCE_WHILE_TRAINING: true SAVE_CHECKPOINTS: true

paths: dataset_dir: ./dataset save_model_as: ./logs/crnn.pth

model: use_attention: true use_ctc: true gray_scale: true dims: 256

GabrielDornelles commented 10 months ago

Can you provide me your inference.py file?

AnishTadepalli commented 10 months ago

Yes, please fine the below attachment.

inference.txt

GabrielDornelles commented 10 months ago

Please rewrite your classes list to the same that was trained, its printed in the terminal as the training starts. The first element in the list MUST be "∅".

I see you also changed a few things in the image processing (mean and std, grayscale convertion), so you need to ensure that you have done this at training code too.

AnishTadepalli commented 10 months ago

Hi, as you mentioned I have modified the training code (mean,std blank char), but still getting the same type of output. I am adding the modified files. train.txt data_loading.txt inference.txt

AnishTadepalli commented 10 months ago

Hi, thanks for your time and responses. Actually at the end of the training I am getting the error as " load state dict Expected state_dict to be dict-like, got <class 'NoneType'>.",because I am giving the training.epochs=25,5. So if the best accuracy is achieved at epoch 18 in experiment 2, without saving the model I am continuing the training loop so the model weights are not loading into the model. I did small modification in train.py. now I am getting proper predictions. train.txt