Python 在Tensorflow中,如何防止在重新分配变量后将该变量从变量转换为张量?

Python 在Tensorflow中,如何防止在重新分配变量后将该变量从变量转换为张量?,python,tensorflow,Python,Tensorflow,这里有一段代码片段。x_hat从tensorflow.python.ops.variables.RefVariable转换为tensorflow.python.framework.ops.Tensor import tensorflow as tf import tensorflow.contrib.slim as slim import tensorflow.contrib.slim.nets as nets tf.logging.set_verbosity(tf.logging.ERROR)

这里有一段代码片段。x_hat从tensorflow.python.ops.variables.RefVariable转换为tensorflow.python.framework.ops.Tensor

import tensorflow as tf
import tensorflow.contrib.slim as slim
import tensorflow.contrib.slim.nets as nets
tf.logging.set_verbosity(tf.logging.ERROR)
sess = tf.InteractiveSession()
image = tf.Variable(tf.zeros((299, 299, 3)))

x = tf.placeholder(tf.float32, shape=[None, None, None])
x_hat = image

print(type(x_hat))
noise = x_hat - x
#filter noise
x_hat = noise + x

print(type(x_hat))
基本上,x_-hat是在会话中修改的(代码未显示),修改后,我想从x_-hat中提取“noise”,修改“noise”,然后将其添加回x_-hat。然而,我编写的代码将x_hat转换为张量,这会在以后破坏事情


我确信我的尝试不是实现我想要的目标的正确方式,那么您有什么建议吗?

以下代码是通过类型更改执行的

x_hat = noise + x
适当的方法:

op = tf.assign(x_hat,noise+x)

执行以下代码时进行了类型更改

x_hat = noise + x
适当的方法:

op = tf.assign(x_hat,noise+x)