Я пытаюсь скопировать этот пример Keras для модели CT C в тензорном потоке 2.1. Тем не менее, я получаю TypeError при вызове функции ctc_batch_cost
:
y_pred = tf.keras.layers.Activation('softmax', name='softmax')(model)
y_true = tf.keras.layers.Input(name='labels', shape=(None,), dtype='float32')
input_lentgh = tf.keras.layers.Input(name='in_len', shape=(1,), dtype=tf.int64)
label_length = tf.keras.layers.Input(name='label_length', shape=(1,), dtype='int64')
loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_lentgh, label_length)
Трассировка:
File "ctc_train.py", line 100, in <module>
loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_lentgh, label_length)
File "$PATH_TO_VENV/venv/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 5758, in ctc_batch_cost
ctc_label_dense_to_sparse(y_true, label_length), dtypes_module.int32)
File "$PATH_TO_VENV/venv/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 5712, in ctc_label_dense_to_sparse
range_less_than, label_lengths, initializer=init, parallel_iterations=1)
File "$PATH_TO_VENV/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/functional_ops.py", line 436, in scan
infer_shape=True) for elem in elems_flat
File "$PATH_TO_VENV/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/functional_ops.py", line 436, in <listcomp>
infer_shape=True) for elem in elems_flat
File "$PATH_TO_VENV/lib/python3.6/site-packages/tensorflow_core/python/ops/tensor_array_ops.py", line 1078, in __init__
name=name)
File "$PATH_TO_VENV/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/tensor_array_ops.py", line 716, in __init__
self._tensor_array = [None for _ in range(size)]
TypeError: 'Tensor' object cannot be interpreted as an integer
Однако типы данных в ctc_batch_cost
должны быть тензорными согласно документации .