2017-08-27 13 views
0

にフィルタの対応する寸法と一致していない、次のコードが番号iがResnet50に基づいてモデルを構築するkerasを使用していKeras

input_crop = Input(shape=(3, 224, 224)) 

# extract feature from image crop 
resnet = ResNet50(include_top=False, weights='imagenet') 
for layer in resnet.layers: # set resnet as non-trainable 
    layer.trainable = False 

crop_encoded = resnet(input_crop) 

下に示されているが、私はエラーが発生しました

'ValueError: number of input channels does not match corresponding dimension of filter, 224 != 3'

どのように修正できますか?

+0

あなたはどのようなバックエンドあなたのkeras.jsonファイルの内容は何ですか? – maz

答えて

3

このようなエラーは、Theano & TensorFlow backends Kerasで使用されている画像フォーマットが異なるため、通常は生成されます。あなたのケースでは、画像は明らかにchannels_firstフォーマット(Theano)にありますが、おそらくあなたはchannels_lastフォーマットでそれらを必要とするTensorFlowバックエンドを使用します。

KerasでMNIST CNN exampleは、このような問題のためにあなたのコードの免疫を作るための良い方法を提供し、すなわちTheano & TensorFlowバックエンドの両方のために働いて - ここでは、あなたのデータのために適応したものです:

from keras import backend as K 

img_rows, img_cols = 224, 224 

if K.image_data_format() == 'channels_first': 
    input_crop = input_crop.reshape(input_crop.shape[0], 3, img_rows, img_cols) 
    input_shape = (3, img_rows, img_cols) 
else: 
    input_crop = input_crop.reshape(input_crop.shape[0], img_rows, img_cols, 3) 
    input_shape = (img_rows, img_cols, 3) 

input_crop = Input(shape=input_shape) 
関連する問題