2016-11-29 2 views
1

ケラスでCNNを書こうとしています。画像/ラベルをロードする最も簡単な方法は、ImageDataGeneratorflow_from_directory()の組み合わせを使用することである私の理解からKeras - ディレクトリ構造から文字列としてラベルを取得する

dataset/ 
    class1/ 
     1.png 
     2.png 
     ... 
    class2/ 
     ... 
    ... 

:私のデータセットは、以下のフォルダ構造と250クラス20,000の画像で構成されています。
最小実施例32は、batch_sizeと250クラスの数であると

Exception: Error when checking model target: expected maxpooling2d_1 to have 4 dimensions, but got array with shape (32, 250) 

from keras.layers import Activation, Convolution2D, MaxPooling2D 
from keras.models import Sequential 
from keras.preprocessing.image import ImageDataGenerator 

if __name__ == '__main__':  
    # input image dimensions 
    img_rows, img_cols = 225, 225 
    input_shape = (img_rows, img_cols, 1) 

    model = Sequential() 
    model.add(Convolution2D(64, 15, 15, input_shape=input_shape, subsample=(3, 3))) 
    model.add(Activation('relu')) 
    model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2))) 

    model.compile(loss='hinge', optimizer='adadelta', metrics=['accuracy']) 

    data = ImageDataGenerator() 
    train_data = data.flow_from_directory(directory='dataset', color_mode='grayscale', target_size=(img_rows, img_cols)) 
    model.fit_generator(train_data, 100, 12) 

しかし、これは次のエラーで停止します。

これは画像/ラベルの取得方法に問題がありますか?

答えて

0

私の問題は、ラベルが文字列ではなく、間違ったCNNアーキテクチャでした。 MaxPooling2Dの後にFlatten()レイヤーを追加すると、ネットの出力を自分のラベルにマップできるようになりました。

関連する問題