Python 运行时错误:CorrMM无法分配576 x 50176的工作内存
我在尝试从VGG19网络(在CPU上运行)提取Keras图像特征时出现内存错误。步幅的价值似乎高得令人难以置信,我不知道它们是什么意思,这可能有关联吗?上传的图像最初为736 x 491,但在送入网络之前已调整为224 x 224Python 运行时错误:CorrMM无法分配576 x 50176的工作内存,python,theano,keras,Python,Theano,Keras,我在尝试从VGG19网络(在CPU上运行)提取Keras图像特征时出现内存错误。步幅的价值似乎高得令人难以置信,我不知道它们是什么意思,这可能有关联吗?上传的图像最初为736 x 491,但在送入网络之前已调整为224 x 224 RuntimeError: CorrMM failed to allocate working memory of 576 x 50176 Apply node that caused the error: CorrMM{half, (1, 1)} (Elemw
RuntimeError: CorrMM failed to allocate working memory of 576 x 50176
Apply node that caused the error: CorrMM{half, (1, 1)} (Elemwise{Composite{(i0 * (Abs((i1 + i2)) + i1 + i2))}}[(0, 1)].0, Subtensor{::, ::, ::int64, ::int64}.0)
Toposort index: 77
Inputs types: [TensorType(float32, 4D), TensorType(float32, 4D)]
Inputs shapes: [(1, 64, 224, 224), (64, 64, 3, 3)]
Inputs strides: [(12845056, 200704, 896, 4), (4, 256, -49152, -16384)]
Inputs values: ['not shown', 'not shown']
Outputs clients: [[Elemwise{Composite{(i0 * (Abs((i1 + i2)) + i1 + i2))}}[(0, 1)](TensorConstant{(1, 1, 1, 1) of 0.5}, CorrMM{half, (1, 1)}.0, InplaceDimShuffle{0,3,1,2}.0)]]
我正在运行的代码:
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
model_features = model.predict(x)
total_sum = sum(model_features[0])
features_norm = np.array([val / total_sum for val in model_features[0]], dtype=np.float32)
形状和模型概述
x shape (1, 3, 224, 224)
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 3, 224, 224) 0
____________________________________________________________________________________________________
block1_conv1 (Convolution2D) (None, 64, 224, 224) 1792 input_1[0][0]
____________________________________________________________________________________________________
block1_conv2 (Convolution2D) (None, 64, 224, 224) 36928 block1_conv1[0][0]
____________________________________________________________________________________________________
block1_pool (MaxPooling2D) (None, 64, 112, 112) 0 block1_conv2[0][0]
____________________________________________________________________________________________________
block2_conv1 (Convolution2D) (None, 128, 112, 112) 73856 block1_pool[0][0]
____________________________________________________________________________________________________
block2_conv2 (Convolution2D) (None, 128, 112, 112) 147584 block2_conv1[0][0]
____________________________________________________________________________________________________
block2_pool (MaxPooling2D) (None, 128, 56, 56) 0 block2_conv2[0][0]
____________________________________________________________________________________________________
block3_conv1 (Convolution2D) (None, 256, 56, 56) 295168 block2_pool[0][0]
____________________________________________________________________________________________________
block3_conv2 (Convolution2D) (None, 256, 56, 56) 590080 block3_conv1[0][0]
____________________________________________________________________________________________________
block3_conv3 (Convolution2D) (None, 256, 56, 56) 590080 block3_conv2[0][0]
____________________________________________________________________________________________________
block3_conv4 (Convolution2D) (None, 256, 56, 56) 590080 block3_conv3[0][0]
____________________________________________________________________________________________________
block3_pool (MaxPooling2D) (None, 256, 28, 28) 0 block3_conv4[0][0]
____________________________________________________________________________________________________
block4_conv1 (Convolution2D) (None, 512, 28, 28) 1180160 block3_pool[0][0]
____________________________________________________________________________________________________
block4_conv2 (Convolution2D) (None, 512, 28, 28) 2359808 block4_conv1[0][0]
____________________________________________________________________________________________________
block4_conv3 (Convolution2D) (None, 512, 28, 28) 2359808 block4_conv2[0][0]
____________________________________________________________________________________________________
block4_conv4 (Convolution2D) (None, 512, 28, 28) 2359808 block4_conv3[0][0]
____________________________________________________________________________________________________
block4_pool (MaxPooling2D) (None, 512, 14, 14) 0 block4_conv4[0][0]
____________________________________________________________________________________________________
block5_conv1 (Convolution2D) (None, 512, 14, 14) 2359808 block4_pool[0][0]
____________________________________________________________________________________________________
block5_conv2 (Convolution2D) (None, 512, 14, 14) 2359808 block5_conv1[0][0]
____________________________________________________________________________________________________
block5_conv3 (Convolution2D) (None, 512, 14, 14) 2359808 block5_conv2[0][0]
____________________________________________________________________________________________________
block5_conv4 (Convolution2D) (None, 512, 14, 14) 2359808 block5_conv3[0][0]
____________________________________________________________________________________________________
block5_pool (MaxPooling2D) (None, 512, 7, 7) 0 block5_conv4[0][0]
____________________________________________________________________________________________________
flatten (Flatten) (None, 25088) 0 block5_pool[0][0]
____________________________________________________________________________________________________
fc1 (Dense) (None, 4096) 102764544 flatten[0][0]
____________________________________________________________________________________________________
fc2 (Dense) (None, 4096) 16781312 fc1[0][0]
====================================================================================================
Total params: 139,570,240
Trainable params: 139,570,240
Non-trainable params: 0
问题在于,
VGG19
体系结构在推理阶段大约需要每个样本250MB
。batch\u size=32的默认值
因此model试图分配8GB
的内存,这比OPs机器的内存多得多。:D-您能打印出x.shape
和model.summary()
?您正试图分配超过6GB的内存-这导致您的RAM
@MarcinMożejko打印出来的内存出现问题:)您的机器有多少RAM
内存?这个错误以前发生过吗?作为第一次尝试,我会这样做:model\u features=model.predict(x,batch\u size=1)