faustomorales / keras-ocr

A packaged and flexible version of the CRAFT text detector and Keras CRNN recognition model.
https://keras-ocr.readthedocs.io/
MIT License
1.37k stars 349 forks source link

Training detector on custom dataset, however model is not detecting anything #192

Open jyha1717 opened 2 years ago

jyha1717 commented 2 years ago

Hi all, having some issues here trying to train detector on my custom dataset.

I have made use of the "Fine-tuning the detector" example as a reference, and labelled my dataset in the required format (i.e. "lines is a list of lines of text in the image where each line is itself a list of tuples of the form ((x1, y1), (x2, y2), (x3, y3), (x4, y4), c). c is the character in the line and (x1, y1), (x2, y2), (x3, y3), (x4, y4) define the bounding coordinates in clockwise order starting from the top left."). However, upon training the model, the detector fails to detect any text in any of my test images. I'd like to know if anybody else has this same issue?

My code snippet is as follows: (annotations are in the VOC format, which I then convert into the required format)

trainfiles = [name for name in listoffiles if not name.startswith('t_')]
testfiles = [name for name in listoffiles if name.startswith('t_')]

datasets = [[],[]] #train, test

for i in range(2):
    listoffiles = [trainfiles,testfiles][i]
    for file in listoffiles:
        annotationfile = annotationfolder + '/' + os.path.splitext(file)[0]+'.xml'
        fullfile = jpgfolder+'/'+file
        objects = ET.parse(annotationfile).findall('object')
        word = []
        for obj in objects:
            class_name = obj.find('name').text.strip()
            bbox = obj.find('bndbox')
            x1 = float(bbox.find('xmin').text) - 1
            y1 = float(bbox.find('ymin').text) - 1
            x2 = float(bbox.find('xmax').text) - 1
            y2 = float(bbox.find('ymax').text) - 1
            coords = np.array([[x1,y1],[x2,y1],[x2,y2],[x1,y2]])
            word.append((coords,class_name))
        datasets[i].append([fullfile,[word],1])

[dataset,test_dataset] = datasets

train, validation = sklearn.model_selection.train_test_split(
    dataset, train_size=0.8, random_state=42
)

and the code continues as in the "Fine-tuning the detector" document.

Madesh1997 commented 1 year ago

which tool you used to annotate the data?

rohan-a99 commented 1 year ago

hey i am also facing the same issue, can someone help, even after training the detector, when i use it in pipeline , it takes the weights of the pretrained model instead of the model i trained with custom data

rohan-a99 commented 1 year ago

any updates anyone