使用keras
model.fit_generator,其中steps_per_epoch表示的是训练多少次一个epoch结束,其中每一次的训练样本数为datagen.flow数据流生成器随机生成的batch_size个数(即batch_size个样本后来一次梯度下降更新参数),按照以往的epoch习惯,建议把steps_per_epoch参数设置为: 原一轮样本个数/batch_size,如果未指定,默认为数据流中的batch_size参数
datagen = ImageDataGenerator(
featurewise_center=False, # set input mean to 0 over the dataset
samplewise_center=False, # set each sample mean to 0
featurewise_std_normalization=False, # divide inputs by std of the dataset
samplewise_std_normalization=False, # divide each input by its std
zca_whitening=False, # apply ZCA whitening
rotation_range=10, # randomly rotate images in the range (degrees, 0 to 180)
zoom_range = 0.1, # Randomly zoom image
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
horizontal_flip=False, # randomly flip images
vertical_flip=False) # randomly flip images
epochs=10
batch_size = 64
datagen.fit(X_train)
model.fit_generator(datagen.flow(X_train,y_train, batch_size=batch_size),
epochs = epochs,
verbose = 1, steps_per_epoch=X_train.shape[0]/batch_size,
callbacks = [callbacks.EarlyStopping(min_delta = 0.005,patience = 2,monitor = 'acc',mode = 'max')])