2017-02-17 98 views
0

我努力訓練使用Keras小CNN與ImageDataGenerator像這樣:Keras錯誤編譯節點

model = Sequential() 

model.add(Convolution2D(32, 3, 3, input_shape=(IM_HEIGHT, IM_WIDTH, 3), activation='relu')) 
model.add(Convolution2D(32, 3, 3, activation='relu')) 
model.add(MaxPooling2D(pool_size=(2, 2))) 
model.add(Flatten()) 
model.add(Dense(1, activation='softmax')) 

model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy']) 

train_datagen = ImageDataGenerator(
    rescale=1./255, 
    shear_range=0.2, 
    zoom_range=0.2, 
    horizontal_flip=True, 
    rotation_range=40, 
    fill_mode='nearest') 

train_generator = train_datagen.flow_from_directory(
    SPLIT_TRAIN_DIR, 
    target_size=(IM_HEIGHT, IM_WIDTH), 
    batch_size=32, 
    class_mode='binary') 

validation_datagen = ImageDataGenerator(rescale=1./255) 
validation_generator = validation_datagen.flow_from_directory(
    SPLIT_VALIDATION_DIR, 
    target_size=(IM_HEIGHT, IM_WIDTH), 
    batch_size=32, 
    class_mode='binary') 

model.fit_generator(
    train_generator, samples_per_epoch=32, nb_epoch=3, verbose=1, 
    validation_data=validation_generator, nb_val_samples=800) 

我試圖解決二元分類問題,但我發現了以下錯誤

例外:(, GpuElemwise {RoundHalfToEven,no_inplace}(GpuSoftmaxWithBias.0) '而編譯節點發生以下錯誤'

後面跟着大量的cuda選項。這是在失敗的行

model.fit_generator(
    train_generator, samples_per_epoch=32, nb_epoch=3, verbose=1, 
    validation_data=validation_generator, nb_val_samples=800) 

我完全失去了作爲對CNN說這個問題是,我已經嘗試了幾種不同的架構,我也驗證了thte ImageDataGenerator工作正常。我一直無法弄清楚問題可能出在哪裏。

我使用Python 3.6.0,Theano 0.8.2和1.2.2 Keras

回答

0

做多一些挖我發現了一個看似無關issue,但有相同的錯誤消息。

顯然,這是特定版本的Theano的問題,並且已經在主分支中修復。運行

pip install --upgrade git+https://github.com/Theano/Theano.git#egg=Theano 

解決了我的問題。