我是基于 GPU 的训练和深度学习模型的新手。我在我的 2 个 Nvidia GTX 1080 GPU 上的 TensorFlow 中运行 cDCGAN(条件 DCGAN)。我的数据集由大约 320,000 张大小为 64*64 的图像和 2,350 个类别标签组成。如果我将批量大小设置为 32 或更大,则会收到如下所示的 OOM 错误。所以我现在使用 10 个批量大小。
tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[32,64,64,2351] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[Node: discriminator/concat = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](_arg_Placeholder_0_0/_41, _arg_Placeholder_3_0_3/_43, discriminator/concat/axis)]]
Caused by op 'discriminator/concat', defined at:
File "cdcgan.py", line 221, in <module>
D_real, D_real_logits = discriminator(x, y_fill, isTrain)
File "cdcgan.py", line 48, in discriminator
cat1 = tf.concat([x, y_fill], 3)
训练非常慢,我知道这取决于批量大小(如果我错了,请纠正我)。如果我这样做help -n 1 nvidia-smi
,我会得到以下输出:
主要GPU:0
使用,因为 Volatile GPU-Util 给我大约 0%-65%,而GPU:1
最大总是 0%-3%。性能GPU:0
总是在 P2 中,而GPU:1
主要是 P8 或有时是 P2。我有以下问题。
为什么我的数据集和模型没有那么大,但在大批量时却出现 OOM 错误?
如何在 TensorFlow 中平等地利用两个 GPU 以提高性能?(从上面的错误来看,GPU:0 似乎立即满了,而 GPU:1 没有被充分利用。这只是我的理解)。
型号详情如下:
发电机:
我有 4 层(完全连接,UpSampling2d-conv2d,UpSampling2d-conv2d,conv2d)。
W1 的形状为 [X+Y, 16 16 128] 即 (2450, 32768), w2 [3, 3, 128, 64], w3 [3, 3, 64, 32], w4 [[3, 3, 32, 1]] 分别
鉴别器
它有五层(conv2d、conv2d、conv2d、conv2d、全连接)。
w1 [5, 5, X+Y, 64] 即 (5, 5, 2351, 64), w2 [3, 3, 64, 64], w3 [3, 3, 64, 128], w4 [2, 2 , 128, 256], [16 16 256, 1]。
会话配置 我也通过提前分配内存
gpu_options = tf.GPUOptions(allow_growth=True)
session = tf.InteractiveSession(config=tf.ConfigProto(gpu_options=gpu_options))