python - TF2 在@tf.function 中枚举参差不齐的张量
问题描述
我的目标是将 RaggedTensor 沿其第一个维度拆分为张量字典。下面的示例代码可以正常工作,直到它被 @tf.function 修饰。然后,它会产生一个令人困惑的错误:ValueError: slice index 2 of dimension 0 out of bounds。对于 '{{node RaggedGetItem_2/strided_slice_2}} ....' 输入形状:[2]、[1]、[1]、[1] 和计算输入张量:输入[1] = <2>,输入[2] = <3>,输入[3] = <1>。
@tf.function
def fn():
a = tf.constant([[1,2,3],
[4,5,6]])
b = tf.constant([[7,8,9],
[10,11,12],
[13,14,15]])
rt = tf.ragged.stack([a, b])
d = {}
for k,x in enumerate(rt):
d.update({str(k):x})
return d
fn()
有人可以解释发生了什么吗?它与python的副作用有关吗?
谢谢!
解决方案
推荐阅读
- css - 可构造样式表是否提供更好的性能?
- docker - 如何设置 TCP 服务后端?
- javascript - 设置状态然后读取状态显示之前的值
- ansible - Ansible 副本 - 如果 dest 目录以或不以 / 结尾有什么区别
- scheme - 如何让我的代码返回值?
- reactjs - 将基于类的组件转换为钩子(gapi API)
- javascript - 调用函数的百分比机会
- python - 'ServiceAccountCredentials.from_json_keyfile_name' 等效于远程 json
- python - 制作了一个随机创建用户名但我无法将用户名分配给列的函数
- java - Firefox 没有得到返回键