buiquangmanhhp1999 / extract-information-from-identity-card

From identity card image, this repo detect 4 corners, align by OpenCV, then detect word in image and recognize word by Transformer OCR.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: Error(s) in loading state_dict for VietOCR:

dndoanh opened this issue · comments

I tried to run server.py and got this error, please help

Many thanks

File "server.py", line 4, in <module> from serve_model import * File "/root/extract-information-from-identity-card/complete/serve_model.py", line 4, in <module> from merged_model import CompletedModel File "/root/extract-information-from-identity-card/complete/merged_model.py", line 94, in <module> model = CompletedModel() File "/root/extract-information-from-identity-card/complete/merged_model.py", line 17, in __init__ self.text_recognition_model = TextRecognition(path_to_checkpoint='./config_text_recognition/transformerocr.pth') File "/root/extract-information-from-identity-card/complete/recognition.py", line 11, in __init__ self.detector = Predictor(self.config) File "/root/extract-information-from-identity-card/complete/predictor.py", line 17, in __init__ model.load_state_dict(torch.load(weights, map_location=torch.device(device))) File "/root/idcard-ocr/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1224, in load_state_dict self.__class__.__name__, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for VietOCR: size mismatch for transformer.embed_tgt.weight: copying a param with shape torch.Size([232, 256]) from checkpoint, the shape in current model is torch.Size([233, 256]). size mismatch for transformer.fc.weight: copying a param with shape torch.Size([232, 256]) from checkpoint, the shape in current model is torch.Size([233, 256]). size mismatch for transformer.fc.bias: copying a param with shape torch.Size([232]) from checkpoint, the shape in current model is torch.Size([233]).

I've already downloaded this weight file as pic below

P/S plz update requirement.txt for uvicorn, fastapi, pyyaml and also vietocr==0.19.0 not existed, I used 0.3.2 instead

Screen Shot 2021-05-15 at 5 43 14 PM

@buiquangmanhhp1999 after reviewed code I've fixed it make it working
As result I see the accuracy is not tobe good, so can you advise me to improve model?

Many thanks

@buiquangmanhhp1999 after reviewed code I've fixed it make it working
As result I see the accuracy is not tobe good, so can you advise me to improve model?

Many thanks

mình cũng đang lỗi như bạn. bạn có thể share fix dc ko ?

@ckpvthuong bạn add skype mình nhé doanhdn1985

@dndoanh do mô hình OCR chưa được huấn luyện trên tập chứng minh thư nên kết quả chưa được tốt nhé bạn ơi. Bạn có thể tuning lại mô hình OCR trên tập chứng minh thư sẽ cho kết quả tốt hơn nhé

after reviewed code I've fixed it make it working
As result I see the accuracy is not tobe good, so can you advise me to improve model?

Many thanks

@dndoanh Anh có thể share fix lỗi này được không ạ, em cũng bị lỗi như vậy

Mình đã cập nhật bản mã nguồn mới nhất, các bạn có thể tải lại mã nguồn để khắc phục lỗi nhé

Hi mn, tui vừa clone source mới nhất rồi nhưng vẫn bị lỗi này. Ai có thể chỉ rõ cho mình cách fix đc k ạ

Hi mn, tui vừa clone source mới nhất rồi nhưng vẫn bị lỗi này. Ai có thể chỉ rõ cho mình cách fix đc k ạ

Hi b, mình cũng gặp lỗi tương tự không biết bạn đã fix đc chưa, có thể hướng dẫn mình được không ạ

Hi mn, tui vừa clone source mới nhất rồi nhưng vẫn bị lỗi này. Ai có thể chỉ rõ cho mình cách fix đc k ạ

Hi b, mình cũng gặp lỗi tương tự không biết bạn đã fix đc chưa, có thể hướng dẫn mình được không ạ

Lâu lắm r mình cũng k nhớ fix như nào nữa >!<