2016-11-01 6 views
2

私は、非イニシアチブデータではなく、非MNIST用の自動エンコーダーを構築しようとしています。 https://blog.keras.io/building-autoencoders-in-keras.htmlを自分のベースに使用してください。しかし、次のエラーが発生しています。ケラスfit_generator生成例外:ジェネレータの出力はタプル(x、y、sample_weight)または(x、y)でなければなりません。見つかった:[[[0.86666673

**Exception: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: [[[[ 0.86666673 0.86666673 0.86666673 ..., 0.62352943 0.627451 
    0.63137257] 
    [ 0.86666673 0.86666673 0.86666673 ..., 0.63137257 0.627451 
    0.627451 ] 
    [ 0.86666673 0.86666673 0.86666673 ..., 0.63137257 0.627451 
    0.62352943] 
    ...,** 

これはオートエンコーダなので、私のデータジェネレータでは、class mode = Noneを使用しました。私のコードは以下の通りです。

from keras.layers import Input, Dense, Convolution2D, MaxPooling2D, UpSampling2D,Activation, Dropout, Flatten 
from keras.models import Model,Sequential 
from keras.preprocessing.image import ImageDataGenerator 
import numpy as np 
import os 
import h5py 


img_width=140 
img_height=140 
train_data_dir=r'SitePhotos\train' 
valid_data_dir=r'SitePhotos\validation' 
input_img = Input(batch_shape=(32,3, img_width, img_width)) 

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

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

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

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



valid_datagen = ImageDataGenerator(rescale=1./255) 
train_datagen = ImageDataGenerator(rescale=1./255) 

train_generator = train_datagen.flow_from_directory(
     train_data_dir, 
     target_size=(img_width, img_height), 
     batch_size=32, 
     class_mode=None, 
     shuffle=True) 


valid_generator = valid_datagen.flow_from_directory(
     valid_data_dir, 
     target_size=(img_width, img_height), 
     batch_size=32, 
     class_mode=None, 
     shuffle=True) 

autoencoder.fit_generator(train_generator, 
       nb_epoch=50,     
       validation_data=valid_generator, 
       samples_per_epoch=113, 
       nb_val_samples=32 
       ) 
+0

あなたはKerasの寸法オーダーであるかどうか確認することはできますか? linuxを使用している場合、設定ファイルは '〜/ .keras/keras.json' – pyan

+0

であり、それは 'th'です。私はWindows PCを使用しているので、theanoは私にとって唯一の選択肢です – skottapa

答えて

1

実際の解決策は、ケルカの問題が明らかに@skottapaです。

https://github.com/fchollet/keras/issues/4260

rodgzillaは、問題を解決しclass_mode = '入力' を追加し、更新ImageDataGeneratorを提供します。

古いKerasバージョンに変更をバックポートすることができます。わずかに変更された画像モジュールは、ここからダウンロードすることができます:

https://gist.github.com/gsdefender/293db0987a800cf1b103b7777966f8af

関連する問題