width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True) datagen.fit(X_train) y_train_matrix = to_categorical(y_train, len(labeltonumber)) y_val_matrix = to_categorical(y_val, len(labeltonumber)) print('[INFO] start training...') if modus == 'train': if worker == 'single': ## use validation fold for validation model.fit_generator(datagen.flow(X_train, y_train_matrix, batch_size=BATCHSIZE), validation_data=[X_val, y_val_matrix], epochs=EPOCHS, steps_per_epoch=STEPS_PER_EPOCH, verbose=1, callbacks=[checkpoint, lr_scheduler, csv_logger]) elif worker == 'parallel': parallel_model.fit_generator( datagen.flow(X_train, y_train_matrix, batch_size=BATCHSIZE), validation_data=[X_val, y_val_matrix], epochs=EPOCHS, steps_per_epoch=STEPS_PER_EPOCH, verbose=1, callbacks=[checkpoint, lr_scheduler, csv_logger]) ###################################### end version basic and balance ################################################### ####################################### run on test set ################################################################
class_mode='categorical') print(train_generator.class_indices) validation_generator = datagen.flow_from_directory(validation_data_dir, classes=cls_folder, target_size=(img_height, img_width), batch_size=batch_size, shuffle=True, class_mode='categorical') filepath = 'ep{epoch:03d}-val_loss{val_loss:.4f}-val_acc{val_acc:.4f}.h5' checkpoint = ModelCheckpoint(os.path.join(saving_path, filepath), monitor='val_loss', verbose=1, save_best_only=False, save_weights_only=True, mode='min', period=1) board = TensorBoard(log_dir='../../tmp/log', histogram_freq=0, embeddings_freq=0, write_images=True) early_stoping = EarlyStopping(monitor='acc', patience=3) model.fit_generator(train_generator, steps_per_epoch=nb_train_samples // batch_size, epochs=epochs, validation_data=validation_generator, validation_steps=nb_validation_samples // batch_size, callbacks=[board, checkpoint, early_stoping])