gpt4 book ai didi

python - 运行时错误: CorrMM failed to allocate working memory of 576 x 50176

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:08 25 4
gpt4 key购买 nike

尝试使用 Keras 从 VGG19 网络(在 CPU 上运行)提取图像特征时出现内存错误。步幅的值似乎非常高,我不确定它们是什么意思,是否有关联?上传的图像最初为 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)} (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 架构在推理阶段每个样本大约需要 250MBbatch_size=32 的默认值,因此模型尝试分配超过 8GB 的内存,这比 OP 机器的内存要多。

关于python - 运行时错误: CorrMM failed to allocate working memory of 576 x 50176,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43227035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com