2017-04-05 14 views
1

VGG19ネットワーク(CPU上で実行中)からKerasを使用して画像機能を抽出しようとすると、メモリエラーが発生します。ストライドの価値は信じられないほど高く見えますが、その意味が何であるか分かりません。アップロードされた画像は最初は736 x 491ですが、ネットワークに挿入する前に224 x 224にサイズ変更されました。私が実行しているRuntimeError:CorrMMが作業メモリ576 x 50176の割り当てに失敗しました

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 
+0

:D - 'x.shape'と' model.summary() 'を出力できますか?あなたは6GBを超えるメモリを割り当てようとしています。これはあなたの 'RAM 'に問題を引き起こします。 –

+0

@MarcinMożejkoはそれらを印刷しました:) –

+0

あなたのマシンにはどのくらいのRAMメモリがありますか?このエラーは以前に発生しましたか? –

答えて

1

問題はそのVGG19アーキテクチャであるが、推論段階で約250MBサンプルあたりを必要とします。 batch_size=32のデフォルト値なので、モデルは8GB以上のメモリを割り当てようとしました。

関連する問題