我正在使用 tensorflow 训练我的第一个多 GPU 模型。正如教程所述,变量使用 name_scope 固定在每个 GPU 上的 CPU 和操作上。
当我正在运行一个小型测试并记录设备放置时,我可以看到操作被放置在带有 TOWER_1/TOWER_0 前缀的相应 GPU 上,但变量没有被放置在 CPU 上。
我是否遗漏了什么,或者我是否错误地理解了设备放置日志。
附上测试代码,这是设备放置日志
谢谢
测试代码
with tf.device('cpu:0'):
imgPath=tf.placeholder(tf.string)
imageString=tf.read_file(imgPath)
imageJpeg=tf.image.decode_jpeg(imageString, channels=3)
inputImage=tf.image.resize_images(imageJpeg, [299,299])
inputs = tf.expand_dims(inputImage, 0)
for i in range(2):
with tf.device('/gpu:%d' % i):
with tf.name_scope('%s_%d' % ('TOWER', i)) as scope:
with slim.arg_scope([tf.contrib.framework.python.ops.variables.variable], device='/cpu:0'):
with slim.arg_scope(inception_v3.inception_v3_arg_scope()):
logits,endpoints = inception_v3.inception_v3(inputs, num_classes=1001, is_training=False)
tf.get_variable_scope().reuse_variables()
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True)) as sess:
tf.initialize_all_variables().run()
exit(0)
编辑 基本上'with slim.arg_scope([tf.contrib.framework.python.ops.variables.variable], device='/cpu:0'):' 行应该强制cpu上的所有变量,但它们是被创建的在“GPU:0”上