I am trying to build an CTC Layer for loss calculation for my Hand written text recognition model, but encountering these errors
TypeError: Exception encountered when calling CTC_Layer.call().
Value passed to parameter 'indices' has DataType float32 not in list of allowed values: uint8, int8, int32, int64
class CTC_Layer(Layer): def __init__(self, name=None): super(CTC_Layer, self).__init__(name='ctc_loss') self.loss_fn = tensorflow.nn.ctc_loss def call(self, y_true, y_pred): batch_length = tf.cast(tf.shape(y_true)[0], "int64") input_length = tf.cast(tf.shape(y_pred)[1], "int64") label_length = tf.cast(tf.shape(y_true)[1], "int64") input_length = input_length * tf.ones(shape=(batch_length,), dtype="int64") label_length = label_length * tf.ones(shape=(batch_length,), dtype="int64") loss = self.loss_fn(y_true, y_pred, input_length, label_length) self.add_loss(loss) return y_pred
Hand written text recognition model consists of 2-D CNN, Bidirectional LSTM
---------------------------------------------------------------------------TypeError Traceback (most recent call last)Cell In[133], line 1----> 1 model = build_model() 2 model.summary()Cell In[132], line 31, in build_model() 24 x = layers.Bidirectional( 25 layers.LSTM(64, return_sequences=True, dropout=0.25) 26 )(x) 28 x = layers.Dense( 29 len((char_to_num.get_vocabulary()))+2, activation='softmax', name='dense2' 30 )(x)---> 31 outputs = CTC_Layer(name="ctc_loss")(labels, x) 34 model = keras.models.Model(inputs=[input_image, labels], outputs=outputs) 36 model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001))File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs) 119 filtered_tb = _process_traceback_frames(e.__traceback__) 120 # To get the full stack trace, call: 121 # `keras.config.disable_traceback_filtering()`--> 122 raise e.with_traceback(filtered_tb) from None 123 finally: 124 del filtered_tbCell In[93], line 15, in CTC_Layer.call(self, y_true, y_pred) 12 input_length = input_length * tf.ones(shape=(batch_length,), dtype="int64") 13 label_length = label_length * tf.ones(shape=(batch_length,), dtype="int64")---> 15 loss = self.loss_fn(y_true, y_pred, input_length, label_length) 16 self.add_loss(loss) 18 # At test time, just return the computed predictions.TypeError: Exception encountered when calling CTC_Layer.call().Value passed to parameter 'indices' has DataType float32 not in list of allowed values: uint8, int8, int32, int64Arguments received by CTC_Layer.call():• args=('<KerasTensor shape=(None, None), dtype=float32, sparse=None, name=label>', '<KerasTensor shape=(None, 32, 79), dtype=float32, sparse=False, name=keras_tensor_317>')• kwargs=<class 'inspect._empty'>]
Does anyone have an idea how to solve this? Thanks in advance!!