Skip to content

Failed to find data adapter that can handle input #30

Open

Description

@philzetter

Hi @pythonlessons,
I'm trying to use the image to word Tutorial.

I changed the train.py a bit in order to read my images and labels better. The only change was in def read_annotation_file:

Old Code:

def read_annotation_file(annotation_path):
   dataset, vocab, max_len = [], set(), 0
    with open(annotation_path, "r") as f:
        for line in tqdm(f.readlines()):
            line = line.split()
            image_path = data_path + line[0][1:]
            label = line[0].split("_")[1]
            dataset.append([image_path, label])
            vocab.update(list(label))
            max_len = max(max_len, len(label))
    return dataset, sorted(vocab), max_len

New Code:

def read_annotation_file(annotation_path):
    dataset, vocab, max_len = [], set(), 0
    with open(annotation_path, "r") as f:
        for line in tqdm(f.readlines()):
            line = line.split(' ')
            image_path = data_path + line[0]
            label = line[1]
            dataset.append([image_path, label])
            vocab.update(list(label))
            max_len = max(max_len, len(label))
    return dataset, sorted(vocab), max_len

I also changed something in line 91 due to an error:

Old Code:
metrics=[CWERMetric()],

New Code:
metrics=[CWERMetric('accuracy')],

This is my error:

Traceback (most recent call last):
File "/path/to/mltu/Tutorials/01_image_to_word/train.py", line 111, in
model.fit(
File "/path/to/.local/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/path/to/.local/lib/python3.10/site-packages/keras/engine/data_adapter.py", line 1083, in select_data_adapter
raise ValueError(
ValueError: Failed to find data adapter that can handle input: <class 'mltu.dataProvider.DataProvider'>, <class 'NoneType'>

How do I need to change train_data_provider or train_dataset or is it a version problem ?

Activity

  1. pythonlessons commented on Aug 8, 2023

    @pythonlessons
    Owner

    Hi, if you followed my tutorial from pylessons.com then you may face a problem with code.

    Use newest mltu library version. And use the right ImageReader, example code:

    # Create training data provider
    train_data_provider = DataProvider(
        dataset=train_dataset,
        skip_validation=True,
        batch_size=configs.batch_size,
        data_preprocessors=[ImageReader(CVImage)],
        transformers=[
            ImageResizer(configs.width, configs.height),
            LabelIndexer(configs.vocab),
            LabelPadding(max_word_length=configs.max_text_length, padding_value=len(configs.vocab))
            ],
    )
    
  2. philzetter commented on Aug 8, 2023

    @philzetter
    Author

    Thank you for the fast response !
    I'm using exactly the same code.
    My train_dataset looks like this:

    [['CINCMC/images/one.jpg', 'one']]

  3. pythonlessons commented on Aug 15, 2023

    @pythonlessons
    Owner

    try to iterate train_data_provider in for loop and check if you receive correct data there

  4. philzetter commented on Aug 16, 2023

    @philzetter
    Author

    Could you sent me an example of your annotation files. I just need a few lines of the txt files. I think that's the problem.

  5. philzetter commented on Aug 23, 2023

    @philzetter
    Author

    I still get this error:

    Traceback (most recent call last):
      File "/path/to/mltu/Tutorials/01_image_to_word/train.py", line 102, in <module>
        model.fit(
      File "/path/to/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
        raise e.with_traceback(filtered_tb) from None
      File "/path/to/python3.10/site-packages/keras/engine/data_adapter.py", line 1083, in select_data_adapter
        raise ValueError(
    ValueError: Failed to find data adapter that can handle input: <class 'mltu.dataProvider.DataProvider'>, <class 'NoneType'>
    

    My dataset in read_annotation_file looks like this:

    [['CINCMC/train_images/word_1001.png', 'KSZU0005183'], ['CINCMC/train_images/word_1002.png', '25G2'], ['CINCMC/train_images/word_1003.png', 'SLRU0001112'], ['CINCMC/train_images/word_1004.png', '25U2'], ['CINCMC/train_images/word_1005.png', 'SLRU0001540'], ['CINCMC/train_images/word_1006.png', 'SLRU0001072'], ['CINCMC/train_images/word_1007.png', '25U2'], ['CINCMC/train_images/word_1008.png', '25U2'], ['CINCMC/train_images/word_1009.png', 'SLRU0000939'], ['CINCMC/train_images/word_1010.png', '25U2'], ['CINCMC/train_images/word_1011.png', '25U2'], ['CINCMC/train_images/word_1012.png', 'SLRU0001046'], ['CINCMC/train_images/word_1013.png', '25U2'], ['CINCMC/train_images/word_1014.png', 'SLRU0000923'], ['CINCMC/train_images/word_1015.png', '25U2'], ['CINCMC/train_images/word_1016.png', 'SLRU0001133'], ['CINCMC/train_images/word_1017.png', '25U2'], ['CINCMC/train_images/word_1018.png', 'SLRU0001386'], ['CINCMC/train_images/word_1019.png', 'SLRU0001473'], ['CINCMC/train_images/word_1020.png', '25U2'], ['CINCMC/train_images/word_1021.png', '25U2'], ['CINCMC/train_images/word_1022.png', 'SLRU0001046'], ['CINCMC/train_images/word_1023.png', 'SLRU0001410'], ['CINCMC/train_images/word_1024.png', '25U2'], ['CINCMC/train_images/word_1025.png', '25U2'], ['CINCMC/train_images/word_1026.png', '25U2'], ['CINCMC/train_images/word_1027.png', 'SLRU0001616'], ['CINCMC/train_images/word_1028.png', 'SLRU0001128'], ['CINCMC/train_images/word_1029.png', 'SLRU0001149'], ['CINCMC/train_images/word_1030.png', '25U2'], ['CINCMC/train_images/word_1031.png', '25U2'], ['CINCMC/train_images/word_1032.png', 'SLRU0001365'], ['CINCMC/train_images/word_1033.png', '25U2'], ['CINCMC/train_images/word_1034.png', 'SLRU0001318'], ['CINCMC/train_images/word_1035.png', '25U2'], ['CINCMC/train_images/word_1036.png', '25U2'], ['CINCMC/train_images/word_1037.png', 'SLRU0001262'], ['CINCMC/train_images/word_1038.png', '25U2']]

    Versions:
    keras 2.13.1
    tensorflow 2.13.0

  6. pythonlessons commented on Aug 23, 2023

    @pythonlessons
    Owner

    you tried to run this:

    for data in train_data_provider:
        print(data[0], data[1])

    Check if it doesn't return None, because it seems like that

  7. philzetter commented on Aug 23, 2023

    @philzetter
    Author

    The result of:

    for data in train_data_provider:
        print(data[0], data[1])
    

    looks like this:

    [[[[102 102 102]
       [103 103 103]
       [104 104 104]
       ...
       [134 134 134]
       [138 138 138]
       [140 140 140]]
    
      [[102 102 102]
       [104 104 104]
       [105 105 105]
       ...
       [134 134 134]
       [138 138 138]
       [140 140 140]]
    
      [[100 100 100]
       [103 103 103]
       [104 104 104]
       ...
       [135 135 135]
       [138 138 138]
       [140 140 140]]
    
      ...
    
      [[ 96  96  96]
       [ 99  99  99]
       [100 100 100]
       ...
       [135 135 135]
       [139 139 139]
       [139 139 139]]
    
      [[ 98  98  98]
       [ 99  99  99]
       [ 99  99  99]
       ...
       [135 135 135]
       [139 139 139]
       [139 139 139]]
    
      [[101 101 101]
       [ 99  99  99]
       [100 100 100]
       ...
       [136 136 136]
       [139 139 139]
       [139 139 139]]]
    
    
     [[[ 98  98  98]
       [100 100 100]
       [ 99  99  99]
       ...
       [175 175 175]
       [175 175 175]
       [174 174 174]]
    
      [[ 98  98  98]
       [ 99  99  99]
       [ 99  99  99]
       ...
       [197 197 197]
       [195 195 195]
       [189 189 189]]
    
      [[ 99  99  99]
       [100 100 100]
       [100 100 100]
       ...
       [197 197 197]
       [197 197 197]
       [203 203 203]]
    
      ...
    
      [[ 99  99  99]
       [100 100 100]
       [103 103 103]
       ...
       [202 202 202]
       [206 206 206]
       [203 203 203]]
    
      [[ 99  99  99]
       [102 102 102]
       [102 102 102]
       ...
       [200 200 200]
       [200 200 200]
       [197 197 197]]
    
      [[100 100 100]
       [100 100 100]
       [101 101 101]
       ...
       [182 182 182]
       [182 182 182]
       [181 181 181]]]
    
    
     [[[127 127 127]
       [127 127 127]
       [127 127 127]
       ...
       [137 137 137]
       [137 137 137]
       [134 134 134]]
    
      [[127 127 127]
       [126 126 126]
       [126 126 126]
       ...
       [136 136 136]
       [136 136 136]
       [134 134 134]]
    
      [[127 127 127]
       [126 126 126]
       [125 125 125]
       ...
       [136 136 136]
       [136 136 136]
       [136 136 136]]
    
      ...
    
      [[126 126 126]
       [125 125 125]
       [125 125 125]
       ...
       [134 134 134]
       [136 136 136]
       [139 139 139]]
    
      [[126 126 126]
       [126 126 126]
       [126 126 126]
       ...
       [136 136 136]
       [138 138 138]
       [138 138 138]]
    
      [[127 127 127]
       [127 127 127]
       [127 127 127]
       ...
       [138 138 138]
       [140 140 140]
       [138 138 138]]]
    
    
     ...
    
    
     [[[113 113 113]
       [112 112 112]
       [114 114 114]
       ...
       [128 128 128]
       [124 124 124]
       [128 128 128]]
    
      [[115 115 115]
       [115 115 115]
       [116 116 116]
       ...
       [146 146 146]
       [135 135 135]
       [129 129 129]]
    
      [[118 118 118]
       [117 117 117]
       [118 118 118]
       ...
       [173 173 173]
       [148 148 148]
       [129 129 129]]
    
      ...
    
      [[115 115 115]
       [116 116 116]
       [121 121 121]
       ...
       [127 127 127]
       [128 128 128]
       [127 127 127]]
    
      [[113 113 113]
       [116 116 116]
       [121 121 121]
       ...
       [127 127 127]
       [127 127 127]
       [127 127 127]]
    
      [[117 117 117]
       [117 117 117]
       [119 119 119]
       ...
       [127 127 127]
       [127 127 127]
       [127 127 127]]]
    
    
     [[[119 119 119]
       [118 118 118]
       [117 117 117]
       ...
       [177 177 177]
       [182 182 182]
       [177 177 177]]
    
      [[119 119 119]
       [120 120 120]
       [121 121 121]
       ...
       [173 173 173]
       [155 155 155]
       [137 137 137]]
    
      ...
    
      [[118 118 118]
       [116 116 116]
       [118 118 118]
       ...
       [125 125 125]
       [127 127 127]
       [127 127 127]]
    
      [[120 120 120]
       [117 117 117]
       [116 116 116]
       ...
       [125 125 125]
       [126 126 126]
       [126 126 126]]
    
      [[121 121 121]
       [118 118 118]
       [116 116 116]
       ...
       [124 124 124]
       [125 125 125]
       [125 125 125]]]] [[ 4  5 16 ... 39 39 39]
     [28 12 23 ...  7  3 39]
     [ 4  5 16 ... 39 39 39]
     ...
     [ 2  5 16 ... 39 39 39]
     [20 27 33 ...  2  8 39]
     [ 2  5 16 ... 39 39 39]]
    
  8. pythonlessons commented on Aug 23, 2023

    @pythonlessons
    Owner

    Looks ok, try to print following:

    for data in train_data_provider:
        if data[0]==None or data[1]==None:
            print("sometwing wrong in data")
        else:
            print(data[0].shape, data[1].shape)
  9. philzetter commented on Aug 23, 2023

    @philzetter
    Author

    Tried the following code:

    for data in train_data_provider:
        if data[0] is None or data[1] is None:
            print("something wrong in data")
        else:
            print(data[0].shape, data[1].shape)
    
    

    Result is:

    (1000, 32, 128, 3) (1000, 12)

    But this was the only line that was printed out

  10. pythonlessons commented on Aug 23, 2023

    @pythonlessons
    Owner

    your batch_size is 1000?

  11. philzetter commented on Aug 23, 2023

    @philzetter
    Author

    1000 is the size of my dataset and I'm loading it as described on to the dataset. I already sent the dataset above.
    Could you maybe show me a few lines of your example annotation file maybe I'm loading the wrong way ....

  12. vaidehidev2 commented on Nov 19, 2024

    @vaidehidev2

    i want to train this model of handwritting sentences on my custom dataset, is it possible?
    how will i generate the text file that is require to train

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions