小编Rez*_*ari的帖子

Tensorflow 中的深度复制

张量流中有深度复制吗?考虑以下操作:

tt = tf.get_variable('t',shape=[2,2])
tt1= tf.identity(tt[0].assign([1,1]))
tt2 = tf.identity(tt[1].assign([2,2]))
Run Code Online (Sandbox Code Playgroud)

我希望 tt1 只编辑 tt 的第一行,tt2 只编辑第二行。这就是我现在得到的:

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(tt1))
    print(sess.run(tt2))
Run Code Online (Sandbox Code Playgroud)

其输出:

 [[ 1.          1.        ]
  [-1.15554953 -0.78545022]]

 [[ 1.  1.]
  [ 2.  2.]].
Run Code Online (Sandbox Code Playgroud)

相反,我想要类似的东西:

 [[ 1.          1.        ]
  [-1.15554953 -0.78545022]]

 [[ -0.31531231 1.6651651]
  [ 2.  2.]].
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,第二个变量也受到第一个分配的影响。有没有办法拥有独立的副本,而不复制对张量的引用?

tensorflow

2
推荐指数
1
解决办法
3032
查看次数

标签 统计

tensorflow ×1