Keras错误编译节点

Keras error compiling node

我正在尝试使用 Keras 和 ImageDataGenerator 训练小型 CNN,如下所示:

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)

我正在尝试解决二元分类问题,但出现以下错误

Exception: ('The following error happened while compiling the node', 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 尝试了几种不同的架构,我还验证了 ImageDataGenerator 工作正常。我还没弄清楚问题出在哪里。

我正在使用 Python 3.6.0、Theano 0.8.2 和 Keras 1.2.2

进一步挖掘我发现了一个看似无关的 issue,但它有相同的错误消息。

显然,这是 Theano 特定版本的问题,并且已经在 master 分支中得到修复。 运行

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

解决了我的问题。