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

别等时光非礼了梦想. 提交于 2020-05-16 22:05:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/61441798/how-to-avoid-defining-target-tensors-in-tensorflow-2-for-ctc-loss-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!