如何避免在 Tensorflow 2 中为 CTC 损失模型定义目标张量? [英] How to avoid defining target tensors in Tensorflow 2 for CTC loss model?

查看:25
本文介绍了如何避免在 Tensorflow 2 中为 CTC 损失模型定义目标张量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Tensorflow 2 中使用 tf.distribute.MirroredStrategy() 在具有 CTC 损失的模型上进行多 GPU 训练.

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

问题是模型需要定义 target_tensors 才能编译.这可能是什么原因?是否有一些解决方法并在不定义 target_tensors 的情况下编译模型?

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

模型是使用 Keras 函数式 API 定义的,例如:

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])

模型必须编译为:

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

该模型有 2 个输出,但第二个使用的 CTC 损失导致了问题.

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

推荐答案

这是通过使用 tf-nightly 版本解决的.

This is solved by using tf-nightly version.

Tf-nightly 不允许在急切执行模式下使用 target_tensors.使用夜间版本,我的模型在没有目标张量的情况下成功编译(实现没有变化),所以问题解决了.

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.

这篇关于如何避免在 Tensorflow 2 中为 CTC 损失模型定义目标张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆