TypeError: You are passing KerasTensor

错误信息:TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='Placeholder:0', description="created by layer 'tf.cast_2'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as `tf.cond`, `tf.function`, gradient tapes, or `tf.map_fn`. Keras Functional model construction only supports TF API calls that *do* support dispatching, such as `tf.math.add` or `tf.reshape`. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer `call` and calling that layer on this symbolic input/output.

解释一下:

这个错误可能是由于你正在使用KerasTensor类型的输入或输出,并尝试将其传递给不支持自定义分发器(如tf.cond、tf.function或tf.map_fn)的TensorFlow API导致的。

要解决此问题,您可以考虑将该操作放入自定义Keras层的call()函数中,并在此层上调用该层的类别,而不是直接使用该函数。这样,您就可以通过输入/输出来执行该操作。

更改操作

在开始两行加入

  1. from tensorflow.python.framework.ops import disable_eager_execution
    
    disable_eager_execution()

即可。 tensorflow 2.12版本   Keras 2.12版本

觉得有用请点个赞支持一下

  • 14
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值