分配带有shape [3075200,512]的张量并在类型为float时使用OOM:为什么?

问题描述

This is the picture using command gpustat -i

And This is the picture using method device_lib.list_local_devices

My model

我正在尝试通过创建灰度图像来使用CNN模型(使用keras)。 我必须尝试使用​​512 * 512的图像大小,但是出现内存溢出错误。 我无法再减小图像的大小,如果我看一下gpustat,它是32GB,但是我不知道为什么会弹出内存错误。我不确定在哪里以及如何找到并增加可分配的gpu内存。

这是我到目前为止所做的尝试。

1。减少一层中的神经元数量 2.使用较小的批次大小(当前批次大小为5) 3.增加要使用的最大池大小 4.增加步幅 5.辍学 6. config = tf.ConfigProto() config.gpu_options.allow_growth =真 7. config = tf.ConfigProto() config.gpu_options.per_process_gpu_memory_fraction 8.策略= tf.distribute.MirroredStrategy() 9. mirrored_strategy = tf.distribute.MirroredStrategy(devices = [“ / GPU:0”,“ / XLA_GPU:1”])

我已经尝试了以上所有方法,但是没有用。如果您知道如何解决,请回答。 您无法缩小图像尺寸。 (这是我实验的目的) 它说GPU内存为32GB,但是如果您让我知道为什么不是32GB时会发生错误,我将不胜感激。

解决方法

简短回答。停止使用Flatten并将其更改为GlobalAveragePooling2DGlobalMaxPooling2D

长答案。您正在尝试使用64*64*800作为Fullyyy太大的Fully Connected图层的输入大小。现代的CNN模型不再使用Flatten并用GlobalAveragePooling2D代替,因为它还保留了CNN可变大小的功能。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...