[英]How can I use the data in a tensor in Tensorflow?
You cannot do this in Tensorflow (pyTorch can do something like this). 您无法在Tensorflow中执行此操作(pyTorch可以执行以下操作)。 The reason is, that TF requires a static graph.
原因是TF需要静态图。 But you are trying to do dynamic evaluations.
但是您正在尝试进行动态评估。 Many people claim this static graph being a disadvantage of TF.
许多人声称此静态图是TF的缺点。 But in fact, it enables many cool features.
但实际上,它启用了许多很酷的功能。 But in you use case it is a little bit cumbersome to get a solution:
但是,在您使用的情况下,获得解决方案有点麻烦:
You need to write it like: 您需要这样写:
z = tf.zeros_like(y1)
label_a = z + 2
label_b = z + 20
case_001 = tf.where(tf.equal(y1, z), z + 2, z)
case_002 = tf.where(tf.equal(y2, z), z + 20, z)
switch_op = tf.where(tf.equal(y1, y2), ..., case_001 + case_002)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.