deep-text-recognition-benchmark icon indicating copy to clipboard operation
deep-text-recognition-benchmark copied to clipboard

length of character_list is diffrent in train and test

Open SHKNS opened this issue 1 year ago • 3 comments

when i train i use this command

!CUDA_VISIBLE_DEVICES=0 python3 train.py --train_data lmdb/training
--valid_data lmdb/validation
--select_data MJ-ST
--batch_ratio 0.5-0.5
--Transformation TPS
--FeatureExtraction ResNet
--SequenceModeling BiLSTM
--Prediction Attn
--saved_model models/TPS-ResNet-BiLSTM-Attn.pth
--FT
--batch_max_length 64
--imgH 50
--imgW 150
--manualSeed 1
--workers 0
--character "0123456789abcdefghijklmnopqrstuvwxyz"

if i use this model in easyocr

is use this .yaml file

network_params: input_channel: 1 output_channel: 512 hidden_size: 256 imgH: 50 lang_list: - 'en' character_list: "0123456789abcdefghijklmnopqrstuvwxyz"

but i get

RuntimeError: Error(s) in loading state_dict for DataParallel: size mismatch for module.Prediction.attention_cell.rnn.weight_ih: copying a param with shape torch.Size([1024, 294]) from checkpoint, the shape in current model is torch.Size([1024, 293]). size mismatch for module.Prediction.generator.weight: copying a param with shape torch.Size([38, 256]) from checkpoint, the shape in current model is torch.Size([37, 256]). size mismatch for module.Prediction.generator.bias: copying a param with shape torch.Size([38]) from checkpoint, the shape in current model is torch.Size([37]).

### in opt.txt

grad_clip: 5 baiduCTC: False select_data: ['MJ', 'ST'] batch_ratio: ['0.5', '0.5'] total_data_usage_ratio: 1.0 batch_max_length: 64 imgH: 50 imgW: 150 rgb: False character: 0123456789abcdefghijklmnopqrstuvwxyz sensitive: False PAD: False data_filtering_off: False Transformation: TPS FeatureExtraction: ResNet SequenceModeling: BiLSTM Prediction: Attn num_fiducial: 20 input_channel: 1 output_channel: 512 hidden_size: 256 num_gpu: 1 num_class: 38

why character is 0123456789abcdefghijklmnopqrstuvwxyz but num_class is 38?

SHKNS avatar Apr 21 '23 01:04 SHKNS

image

no [GO] in my dataset

SHKNS avatar Apr 21 '23 02:04 SHKNS

you got it done ? I have the same problem

sh1man999 avatar Nov 08 '23 11:11 sh1man999

because if you use prediction model attn, EOS(End of Sentence), SOS(Start of Sentence) classes automatically added to your character_list. you can find this at: for gt, pred, confidence in zip(labels[:5], preds[:5], confidence_score[:5]): if 'Attn' in opt.Prediction: gt = gt[:gt.find('[s]')] pred = pred[:pred.find('[s]')] also, if you use CTC, 'blank' class(it is not same with 'white space') added.

so if you use CTC, your class_num increases by 1, Attn, your class_num increases by 2.

Victini00 avatar Jun 21 '24 05:06 Victini00