尝试实现超分辨率模型时出现内存不足错误

时间:2019-03-05 12:20:03

标签: python machine-learning keras neural-network

我想了解如何使用卷积神经网络为高分辨率生成低分辨率图像。

是否有必要在网络上使用较小的输入图像,而输出的图像尺寸是原来的两倍?

我制作了以下模型:

w,h,c=x_train[0].shape


input = Input(shape=(w,h,c),name='LR')
x = UpSampling2D(size=(2,2), name='UP')(input)
h = Dense(720, activation='relu', name ='hide')(x)
h2= Dense(1280, activation='relu', name ='hide2')(h)
output= Dense(3, activation='relu', name ='output')(h2)


model = Model(inputs=input, outputs=output)
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
model.fit(x_train,y_train, epochs=50, verbose=0)

Y_train的大小是x_train的两倍。

但是我收到以下错误消息:

ResourceExhaustedError: OOM when allocating tensor with shape[4608000,720] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
     [[{{node hide/MatMul}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

这种内存不足(OOM)错误是典型的大批处理大小,根本无法容纳到您的内存中。

  

我做了model.fit(x_train,y_train,batch_size=1024, epochs=50, verbose=0)   并且结果超过了系统内存的10%。

1024的声音太大了。从 small 开始(例如〜64),然后以2的幂逐渐增加(例如128、256 ...),直到获得足够大的批量大小,仍然可以容纳您的内存。

How to calculate optimal batch size中的一般性讨论也可能会有所帮助...

相关问题