pythontensorflowkerastensorflow2.0ctc

How to avoid defining target tensors in Tensorflow 2 for CTC loss model?


I am trying to use tf.distribute.MirroredStrategy() for multi GPU training in Tensorflow 2, on a model with CTC loss.

Problem is that model needs defining target_tensors in order to compile. What can be the cause of that? Is there some workaround and compile model without defining target_tensors?

If I do not pass the targets I get the following:

TypeError: Value passed to parameter 'indices' has DataType float32 not in list of allowed values: uint8, int32, int64

The model is defined using Keras functional API by using something like:

model = Model(name ='Joined_Model_2',inputs=self.inp, outputs=[self.network.outp, self.network.outp_stt])

The model must be compiled as:

self.model_joined.compile(optimizer=optimizer_stt,
            loss=losses,
            loss_weights= lossWeights,
            target_tensors=[target1, target2]                      
            )

The model has 2 outputs, but the CTC loss used on the second one is causing the problem.


Solution

  • This is solved by using tf-nightly version.

    Tf-nightly doesn't allow using target_tensors in eager execution mode. With nightly version my model successfully compiled without target tensors (no changes in implementation), so the problem is solved.