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

Unable to Use Custom Trained Model

Open shashi1006 opened this issue 7 months ago • 0 comments

my train command:

CUDA_VISIBLE_DEVICES=0 python3 train.py
--train_data data/cropped_images_lmdb
--valid_data data/cropped_images_lmdb
--Transformation None
--FeatureExtraction VGG
--SequenceModeling BiLSTM
--Prediction CTC
--num_iter 1000

i got

(env) ubuntu@ip-172-31-11-70:~/ocr/deep-text-recognition-benchmark/saved_models/None-VGG-BiLSTM-CTC-Seed1111$ ls best_accuracy.pth best_norm_ED.pth iter_1000.pth iter_2000.pth log_dataset.txt log_train.txt opt.txt

after this i have moved best_accuracy.pth to /home/ubuntu/.EasyOCR/model as custom_example.pth. and

my /home/ubuntu/.EasyOCR/user_network/custom_example.yaml network_params: input_channel: 1 output_channel: 256 hidden_size: 256 imgH: 64 lang_list: - 'en' character_list: 0123456789!"#$%&'()*+,-./:;<=>?@[]^_`{|}~ €ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

it also have custom_example.py which is downloaded from custom_example.zip

when i try to use this in easyocr

python3 ocr.py Traceback (most recent call last): File "/home/ubuntu/ocr/deep-text-recognition-benchmark/ocr.py", line 3, in reader = easyocr.Reader(['en'], recog_network='custom_example') File "/home/ubuntu/ocr/deep-text-recognition-benchmark/env/lib/python3.10/site-packages/easyocr/easyocr.py", line 231, in init self.recognizer, self.converter = get_recognizer(recog_network, network_params,
File "/home/ubuntu/ocr/deep-text-recognition-benchmark/env/lib/python3.10/site-packages/easyocr/recognition.py", line 182, in get_recognizer model.load_state_dict(torch.load(model_path, map_location=device, weights_only=False)) File "/home/ubuntu/ocr/deep-text-recognition-benchmark/env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2581, in load_state_dict raise RuntimeError( RuntimeError: Error(s) in loading state_dict for DataParallel: size mismatch for module.FeatureExtraction.ConvNet.0.weight: copying a param with shape torch.Size([64, 1, 3, 3]) from checkpoint, the shape in current model is torch.Size([32, 1, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.0.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([32]). size mismatch for module.FeatureExtraction.ConvNet.3.weight: copying a param with shape torch.Size([128, 64, 3, 3]) from checkpoint, the shape in current model is torch.Size([64, 32, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.3.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([64]). size mismatch for module.FeatureExtraction.ConvNet.6.weight: copying a param with shape torch.Size([256, 128, 3, 3]) from checkpoint, the shape in current model is torch.Size([128, 64, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.6.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([128]). size mismatch for module.FeatureExtraction.ConvNet.8.weight: copying a param with shape torch.Size([256, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([128, 128, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.8.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([128]). size mismatch for module.FeatureExtraction.ConvNet.11.weight: copying a param with shape torch.Size([512, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([256, 128, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.12.weight: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.12.bias: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.12.running_mean: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.12.running_var: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.14.weight: copying a param with shape torch.Size([512, 512, 3, 3]) from checkpoint, the shape in current model is torch.Size([256, 256, 3, 3]). size mismatch for module.FeatureExtraction.ConvNet.15.weight: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.15.bias: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.15.running_mean: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.15.running_var: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.FeatureExtraction.ConvNet.18.weight: copying a param with shape torch.Size([512, 512, 2, 2]) from checkpoint, the shape in current model is torch.Size([256, 256, 2, 2]). size mismatch for module.FeatureExtraction.ConvNet.18.bias: copying a param with shape torch.Size([512]) from checkpoint, the shape in current model is torch.Size([256]). size mismatch for module.SequenceModeling.0.rnn.weight_ih_l0: copying a param with shape torch.Size([1024, 512]) from checkpoint, the shape in current model is torch.Size([1024, 256]). size mismatch for module.SequenceModeling.0.rnn.weight_ih_l0_reverse: copying a param with shape torch.Size([1024, 512]) from checkpoint, the shape in current model is torch.Size([1024, 256]). size mismatch for module.Prediction.weight: copying a param with shape torch.Size([68, 256]) from checkpoint, the shape in current model is torch.Size([97, 256]). size mismatch for module.Prediction.bias: copying a param with shape torch.Size([68]) from checkpoint, the shape in current model is torch.Size([97]).

cat ocr.py import easyocr

reader = easyocr.Reader(['en'], recog_network='custom_example') result = reader.readtext('./img.jpg') print("Result:", result)

shashi1006 avatar Mar 23 '25 12:03 shashi1006