2017-05-12 14 views
0

私はTheanoバックエンドでKeras自動コードを使用しています。また、720x1080 RGBイメージの自動エンコードを行いたい。 これは私のコードKeras:入力チェック時のエラー

from keras.datasets import mnist 
import numpy as np 
from keras.layers import Input, LSTM, RepeatVector, Conv2D, MaxPooling2D, UpSampling2D 
from keras.models import Model 

from PIL import Image 


x_train = [] 
x_train_noisy = [] 

for i in range(5,1000): 
    image = Image.open('data/trailerframes/frame' + str(i) + '.jpg', 'r') 
    x_train.append(np.array(image)) 
    image = Image.open('data/trailerframes_avg/frame' + str(i) + '.jpg', 'r') 
    x_train_noisy.append(np.array(image)) 


x_train = np.array(x_train) 
x_train = x_train.astype('float32')/255. 
x_train_noisy = np.array(x_train_noisy) 
x_train_noisy = x_train_noisy.astype('float32')/255. 


input_img = Input(shape=(720, 1080, 3)) 
x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img) 
x = MaxPooling2D((2, 2), padding='same')(x) 
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x) 
encoded = MaxPooling2D((2, 2), padding='same')(x) 

x = Conv2D(32, (3, 3), data_format="channels_last", activation='relu', padding='same')(encoded) 
x = UpSampling2D((2, 2))(x) 
x = Conv2D(32, (3, 3), data_format="channels_last", activation='relu', padding='same')(x) 
x = UpSampling2D((2, 2))(x) 
decoded = Conv2D(1, (3, 3), data_format="channels_last", activation='sigmoid', padding='same')(x) 

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

autoencoder.fit(x_train_noisy, x_train, 
      epochs=10, 
      batch_size=128, 
      shuffle=True, 
      validation_data=(x_train_noisy, x_train)) 

ですが、それは私にエラーを与える

ValueError: Error when checking input: expected input_7 to have shape (None, 720, 1080, 3) but got array with shape (995, 720, 1280, 3)

答えて

1

入力エラー:(あなたとあなたの入力を定義し

  • :として

    として、単純な720,1080,3)

  • あなたはそれらの

ワン(720,1280,3)形式のデータを使用してモデルをトライアンしようとしている間違っている、と私はそれが入力のタイプミスだと思う:

#change 1080 for 1280 
input_img = Input(shape=(720, 1280, 3)) 

出力誤差(ターゲット):今すぐ

は、ターゲット・データは、(720,1280,3)のような形をしている、とあなたの最後の層の出力は、(720,1280,1)

簡単な修正は次のとおりです。

decoded = Conv2D(3, (3, 3), data_format="channels_last", activation='sigmoid', padding='same')(x) 

エンコーダを使用して:そのモデルを訓練した後

を、あなただけのエンコーダやデコーダを使用するためのサブモデルを作成することができます。

encoderModel = Model(input_img, decoded)  

decoderInput = Input((shape of the encoder output))  
decoderModel = Model(decoderInput,decoded)) 

これらの2つのモデルがまったく同じを共有しますモデル全体の重み、1つのモデルのトレーニングは3つのモデルすべてに影響します。

トレーニングなしで使用する場合は、model.predict(data)を使用してトレーニングを受けることなく結果を得ることができます。

+0

私はそれを – Gor

+0

とValueErrorを変更し、あなたに をありがとうございます。エラーターゲットをチェック:期待される形状を有するようにconv2d_78(なし、720、1280、1)が、形状を持つ配列を得た(995、720、1280、3) – Gor

+0

しかし、私はまだ取得エラー – Gor

関連する問題