我有一个具有两个不同输出流的卷积神经网络:
input
|
(...) <-- several convolutional layers
|
_________
(several layers) | | (several layers)
fully-connected | | fully-connected
output stream 1 -> | | <- output stream 2
我想计算/gpu:0
上的流1和/gpu:1
上的流2。不幸的是,我不能正确地设置它。在
这次尝试:
^{pr2}$运行速度非常慢(比单独在1个GPU上训练慢),有时会在输出中产生NaN值。我想这可能是因为with
语句可能没有正确同步。所以我添加了control_dependencies
,并将conv层显式地放在/gpu:0
上:
...placeholders... # x -> input, y -> labels
with tf.device("/gpu:0"):
with tf.control_dependencies([x, y]):
...conv layers...
h_conv_flat = tf.reshape(h_conv_last, ...)
with tf.device("/gpu:0"):
with tf.control_dependencies([h_conv_flat]):
...stream 1 layers...
nn_out_1 = tf.matmul(...)
with tf.device("/gpu:1"):
with tf.control_dependencies([h_conv_flat]):
...stream 2 layers...
nn_out_2 = tf.matmul(...)
…但用这种方法,网络甚至无法运行。不管我做了什么,它都抱怨输入没有初始化:
tensorflow.python.framework.errors.InvalidArgumentError:
You must feed a value for placeholder tensor 'x'
with dtype float
[[Node: x = Placeholder[dtype=DT_FLOAT, shape=[],
_device="/job:localhost/replica:0/task:0/cpu:0"]()]]
没有with
语句,网络只对/gpu:0
进行训练,运行合理的东西,没有错误。在
我做错什么了?TensorFlow是否无法将一个网络中的不同层流拆分到不同的GPU?我是否总是要在不同的塔台上分割完整的网络?在
有一个例子说明如何在一个网络上使用多个gpu https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/cifar10/cifar10_multi_gpu_train.py 也许你可以复制代码。 也可以得到这样的东西
看:https://www.tensorflow.org/versions/r0.7/how_tos/using_gpu/index.html#using-multiple-gpus
谨致问候
相关问题 更多 >
编程相关推荐