我在处理一些张量流代码(v1.13.1)时注意到了这种微妙之处:
tf.enable_eager_execution()
for n in Dataset.from_tensor_slices(([1, 2], [3, 4])).make_one_shot_iterator():
print(n)
#
# prints:
# (<tf.Tensor: id=8, shape=(), dtype=int32, numpy=1>, <tf.Tensor: id=9, shape=(), dtype=int32, numpy=3>)
# (<tf.Tensor: id=12, shape=(), dtype=int32, numpy=2>, <tf.Tensor: id=13, shape=(), dtype=int32, numpy=4>)
#
for n in Dataset.from_tensor_slices([[1, 2], [3, 4]]).make_one_shot_iterator():
print(n)
#
# prints:
# tf.Tensor([1 2], shape=(2,), dtype=int32)
# tf.Tensor([3 4], shape=(2,), dtype=int32)
#
Run Code Online (Sandbox Code Playgroud)
上面的区别是第一个循环传递元组中的两个张量,第二个循环传递列表中的两个张量。我预计第二个循环的工作方式与第一个循环相同,对张量进行切片。这是 tf 处理传入元组和列表的方式故意不同吗?
| 归档时间: |
|
| 查看次数: |
1872 次 |
| 最近记录: |