如何更改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)
Run Code Online (Sandbox Code Playgroud)
这造成在GPU上一个新的变量和不改变设备分配一个
我尝试通过使用强制变量重用
tf.get_variable_scope().reuse_variables()
Run Code Online (Sandbox Code Playgroud)
这是代码:
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)
Run Code Online (Sandbox Code Playgroud)
这造成在GPU上一个新的变量和不改变设备分配一个
这次,我收到一条错误消息,说变量a在gpu中不存在。
在更改设备放置或惰性设备分配方面的任何帮助将不胜感激。谢谢
| 归档时间: |
|
| 查看次数: |
1223 次 |
| 最近记录: |