更改现有tensorflow变量的设备放置

时间:2017-02-17 14:33:31

标签: tensorflow

如何更改tf.Variable()的设备位置? 我尝试了两种方法

a = tf.Variable(1,name = 'a')  # a's device is not set
with tf.device('/gpu:0'):
    a = tf.get_variable('a',1)   

这会在gpu上创建一个新变量,并且不会更改 a

的设备分配

我尝试使用

强制执行变量重用
tf.get_variable_scope().reuse_variables()

以下是代码:

a = tf.Variable(1,name = 'a')  # a's device is not set
tf.get_variable_scope().reuse_variables()
with tf.device('/gpu:0'):
    a = tf.get_variable('a',1)   

这会在gpu上创建一个新变量,并且不会更改 a

的设备分配

这一次,我收到错误消息,说明gpu中不存在变量 a

任何有关更改设备放置或延迟设备分配的帮助都将受到赞赏。感谢

0 个答案:

没有答案