ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

Model Training trainModel() after setModelTypeAsYOLOv3() failure incase of Non-English character

Open vmdhhh opened this issue 3 years ago • 5 comments

If the image name and name of annotation xml contains any character from language other than english (e.g German Umlaut, french) the model trainer fails with a following error: UnknownError: error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

vmdhhh avatar May 15 '21 18:05 vmdhhh

Can you give an example what you mean by that

PS (du kannst auch auf dt mit mir schreiben?)

ekesdf avatar May 15 '21 18:05 ekesdf

Sorry for not being clear the first time. Currently, I am training YOLOv3 on a custom dataset. I have about 500 images (jpg, png) and their annotations(xml). Some images have non-english character in their name as e.g 1200px-Paso_de_cebra_en_el_centro_de_Ciudad_de_México.jpg this image has é in it. When i try to run trainmodel() on dataset containing such images it gives error as follows: cv2.error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' [[{{node PyFunc}}]]

Hope its clear now :)

vmdhhh avatar May 15 '21 18:05 vmdhhh

Do you know OpenCV? It is a library which is used to manipulate images and perform simple vision task like pattern matching. The function that opens the image in OpenCV just supports Unicode so all normal characters like you said from the "English" Alphabet. But there is a replacement in Unicode for each letter that exist like é is %E9 and so on. So there are only 2 options one of them is to rewrite the image preprocessing from Image Ai to for example **Pillow ** (does the same thing but support every character) or replace all your bad characters in your annotations and image names. The 2nd idea is probably the best bc rewriting this program will take longer and far more work than just iterating over all your images and replace all those "bad" characters.

ekesdf avatar May 15 '21 18:05 ekesdf

Actually I looked a little in to the code, and it should be relatively easy to change it :thinking:

ekesdf avatar May 15 '21 19:05 ekesdf

I fixed it :partying_face: :partying_face: :partying_face: :partying_face:

generator.txt this is the file where I had to change just 3 lines, and it worked. The only downside is that you can only use RGB image. So Only Images with 3 Channels like [255,255,255] and not like [255]

here is the path to the file you have to replace Path_to_your_Python_install/python3.8/site-packages/imageai

ekesdf avatar May 15 '21 20:05 ekesdf