如何更改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 。
任何有关更改设备放置或延迟设备分配的帮助都将受到赞赏。感谢