0

I was working for OCR model applied to word mnist dataset from Kaggle in colab. I was inspiring by the model from ocr captcha with LSTM and CTC layer authored by A_K_Nain in Keras examples hosted in the site :https://keras.io/examples/vision/captcha_ocr/

It was working for me. but now I have a lot of problems in codind and decoding characters to and from number. And I tried to compilate the model in the site of ocring captcha and I found same problems. Can anyone explain what is the problem and if there is anyway to fix the problem.

I think the problem is in the following code:

Mapping characters to integers

char_to_num = layers.experimental.preprocessing.StringLookup(
    vocabulary=list(characters), num_oov_indices=0, mask_token=None
)

Mapping integers back to original characters

num_to_char = layers.experimental.preprocessing.StringLookup(
    vocabulary=char_to_num.get_vocabulary(), mask_token=None, invert=True
)

which maybe present some problems in his function.

Random Davis
  • 6,662
  • 4
  • 14
  • 24

1 Answers1

0

Removing num_oov_indices=0 and mask_token=None worked for me.

Mapping characters to integers


char_to_num = layers.experimental.preprocessing.StringLookup(
    vocabulary=list(characters))

Mapping integers back to original characters

num_to_char = layers.experimental.preprocessing.StringLookup(
    vocabulary=char_to_num.get_vocabulary(),invert=True
)

Here is the tutorial from tensor flow documentation.

Forward and inverse lookup pairs

This example demonstrates how to use the vocabulary of a standard lookup layer to create an inverse lookup layer.

data = tf.constant([["a", "c", "d"], ["d", "z", "b"]])
layer = StringLookup(vocabulary=vocab)
i_layer = StringLookup(vocabulary=vocab, invert=True)
int_data = layer(data)
i_layer(int_data)
Fhunmie
  • 1
  • 5