2017-09-27 12 views
1

画像は391 x 400です。私は、hereのようにオートエンコーダーを使用しようとしました。ケラスのオートエンコーダーの最後のレイヤーで切り取る

具体的には、私は次のコードを使用しています

from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D 
from keras.models import Model 
from keras import backend as K 

input_img = Input(shape=(391, 400, 1)) # adapt this if using `channels_first` image data format 

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img) 
x = MaxPooling2D((2, 2), padding='same')(x) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
x = MaxPooling2D((2, 2), padding='same')(x) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
encoded = MaxPooling2D((2, 2), padding='same')(x) 

# at this point the representation is (4, 4, 8) i.e. 128-dimensional 

x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded) 
x = UpSampling2D((2, 2))(x) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
x = UpSampling2D((2, 2))(x) 
x = Conv2D(16, (3, 3), activation='relu', padding='same')(x) 
x = UpSampling2D((2, 2))(x) 
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x) 

autoencoder = Model(input_img, decoded) 
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy') 

私は取得していますが、以下:

ValueError: Error when checking target: expected conv2d_37 to have shape (None, 392, 400, 1) but got array with shape (500, 391, 400, 1) 

は私が必要なもの:/クロップ/ドロップからの最後の層を作り変えるでしょう層を392 x 400391 x 400

ありがとうございました。

答えて

1

というレイヤーがあります。タプル((1, 0), (0, 0))は、上から1行をトリミングすることを意味し

cropped = Cropping2D(cropping=((1, 0), (0, 0)))(decoded) 
autoencoder = Model(input_img, cropped) 

392 x 400から391 x 400への最後の層をトリミングするには、次の方法でそれを使用することができます。下から切り抜く場合は、((0, 1), (0, 0))を代わりに使用してください。 cropping引数の詳細については、documentationを参照してください。

関連する問題