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

ValueError: setting an array element with a sequence. #13

Closed RobertLee0522 closed 7 months ago

RobertLee0522 commented 7 months ago

The error message "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (119,) + inhomogeneous part." indicates that there is an issue with setting an array element with a sequence. It suggests that the shape of the array is not homogeneous after the first dimension, with a detected shape of (119,) plus an inhomogeneous part.

I encountered this error while training using the provided data, and I'm unsure about the cause. I have installed the dependencies listed in the requirements.txt file, and my CUDA version is 12.1.

Could you please provide assistance in resolving this issue?

I appreciate any help or suggestions you can provide. Thank you.

GabrielDornelles commented 7 months ago

Your dataset is probably with a variable number of characters per image (like some images are 4 chars, others 6, others 5 etc). To train with Cross Entropy this padding is done automatically by the code, to train with CTC loss (default) you have to choose a character to represent empty space and pad them manually (either in code or outside of it).

If "_" or "-" are not characters you want to predict for example, you could pad your dataset with one of them (always using the max characters for reference).

Example:

cute.png > cute----.png house.png > house---.png pipeline.png > pipeline.png

Then everything has 8 characters, and your array will have fixed size.

RobertLee0522 commented 7 months ago

@GabrielDornelles Thank you for your response, and your answer is correct. When I adjusted the length of each filename to be the same, the program ran smoothly without errors. Additionally, I encountered the error "AssertionError: Torch not compiled with CUDA enabled," which was due to a mismatch between the CUDA version and the Torch version. The solution was to download the corresponding Torch version from https://download.pytorch.org/whl/torch/ and then execute pip install yourpath/downloadfile.wph, which allowed the program to run successfully.

Finally, I must say your training UI design is fantastic, and I absolutely love it.