Keras / Tensorflow模型为所有内容返回零

时间:2017-01-04 22:30:16

标签: tensorflow keras

我有四个变量train_X, train_Y, test_X, test_Y,其中train_X, train_Y是训练集,test_X, test_Y是测试集。我有以下Keras神经网络

from keras.models import Sequential, Model
from keras.optimizers import RMSprop
from keras.layers import Input, Dense, Convolution2D, LSTM, MaxPooling2D, \
                            UpSampling2D, RepeatVector, Flatten, Dropout, Activation
from keras.callbacks import TensorBoard
from keras.preprocessing.image import ImageDataGenerator

idg = ImageDataGenerator()
nb_epoch = 25
idg.fit(train_X)

input_data = Input(shape=(100, 100, 1))
conv1 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(input_data)
pool1 = MaxPooling2D((2, 2), border_mode='same')(conv1)

conv2 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(pool1)
pool2 = MaxPooling2D((2, 2), border_mode='same')(conv2)

conv3 = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(pool2)
pool3 = MaxPooling2D((2, 2), border_mode='same')(conv3)

flatten = Flatten()(pool3)
dense1 = Dense(64)(flatten)
activation = Activation('relu')(dense1)
dropout = Dropout(0.5)(activation)
dense2 = Dense(1)(dropout)
output_data = Activation('sigmoid')(dense2)

model = Model(input_data, output_data)
model.compile(optimizer='adadelta', loss='mean_squared_error')

model.fit_generator(idg.flow(train_X, train_Y, batch_size=32, seed = 0),
                    samples_per_epoch = len(train_X), nb_epoch = nb_epoch,
                   validation_data = (test_X, test_Y), callbacks = [TensorBoard(log_dir='log_dir')])

但是,以下行给了我一切零:

predictions = model.predict(test_X)

我检查了明显的事情,例如test_X为零。我的猜测是问题是某种消失的梯度问题。任何帮助表示赞赏;谢谢!

0 个答案:

没有答案