Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to find data adapter that can handle input #30

Open
philzetter opened this issue Aug 8, 2023 · 11 comments
Open

Failed to find data adapter that can handle input #30

philzetter opened this issue Aug 8, 2023 · 11 comments

Comments

@philzetter
Copy link

philzetter commented Aug 8, 2023

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 ?

@pythonlessons
Copy link
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))
        ],
)

@philzetter
Copy link
Author

philzetter commented Aug 8, 2023

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

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

@pythonlessons
Copy link
Owner

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

@philzetter
Copy link
Author

philzetter commented Aug 16, 2023

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.

@philzetter
Copy link
Author

philzetter commented Aug 23, 2023

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

@pythonlessons
Copy link
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

@philzetter
Copy link
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]]

@pythonlessons
Copy link
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)

@philzetter
Copy link
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

@pythonlessons
Copy link
Owner

your batch_size is 1000?

@philzetter
Copy link
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 ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants