怎样防止在Tensorflow中重新赋值之后,变量被转换为张量?

2024-10-03 02:35:14 发布

您现在位置:Python中文网/ 问答频道 /正文

这里有一段代码片段。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))

基本上,xuhat是在会话中修改的(代码没有显示),修改之后,我想从xuhat中提取“noise”,修改“noise”,然后将其添加回xuhat。然而,我编写的代码将xïhat转换为Tensor,这会在以后破坏一些东西

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


Tags: 代码importnoneloggingtftensorflowhatas