return model def train_network(model, train_generator, validation_generator): model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=1e-4), metrics=["accuracy"]) history = model.fit_generator( train_generator, steps_per_epoch=train_generator.samples / train_generator.batch_size, epochs=30, validation_data=validation_generator, validation_steps=validation_generator.samples / validation_generator.batch_size, verbose=2) return history if __name__ == '__main__': preprocessor = DataPreprocessor.DataPreprocessor() model = built_cnn() #model = loader.load_model_from_json('3_conv_adam_1e-3_cat_cross_v2.json', '3_conv_adam_1e-3_cat_cross_v2.h5') train_generator, validation_generator = preprocessor.get_image_generators() history = train_network(model, train_generator, validation_generator) loader.save_model(model, '3_conv_adam_1e-3_cat_cross_v2.json', '3_conv_adam_1e-3_cat_cross_v2.h5') #plot.plot_model(model, 'cnn_3_conv_RMSProp_1e-4.png') plot.plot_history(history)
def train_network(model, train_generator, validation_generator): model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=1e-4), metrics=["accuracy"]) history = model.fit_generator( train_generator, steps_per_epoch=train_generator.samples / train_generator.batch_size, epochs=20, validation_data=validation_generator, validation_steps=validation_generator.samples / validation_generator.batch_size, verbose=2) return history if __name__ == '__main__': preprocessor = DataPreprocessor.DataPreprocessor() #model = built_cnn() model = loader.load_model_from_json('3_conv_adam_1e-4_cat_cross.json', '3_conv_adam_1e-4_cat_cross.h5') train_generator, validation_generator = preprocessor.get_image_generators() history = train_network(model, train_generator, validation_generator) loader.save_model(model, '3_conv_adam_1e-4_cat_cross.json', '3_conv_adam_1e-4_cat_cross.h5') #plot.plot_model(model, 'cnn_3_conv_RMSProp_1e-4.png') plot.plot_history(history)
def train_network(model, train_generator, validation_generator): model.compile( loss='categorical_crossentropy', optimizer=Nadam(lr=1e-4), metrics=["accuracy"] ) history = model.fit_generator( train_generator, steps_per_epoch=train_generator.samples / train_generator.batch_size, epochs=30, validation_data=validation_generator, validation_steps=validation_generator.samples / validation_generator.batch_size, verbose=2 ) return history if __name__ == '__main__': preprocessor = DataPreprocessor.DataPreprocessor() model = built_cnn() #model = loader.load_model_from_json('3_conv_adam_1e-3_cat_cross_v2.json', '3_conv_adam_1e-3_cat_cross_v2.h5') train_generator, validation_generator = preprocessor.get_image_generators() history = train_network(model, train_generator, validation_generator) loader.save_model(model, '3_conv_nadam_1e-4_v2.json', '3_conv_nadam_1e-4_v2.h5') #plot.plot_model(model, 'cnn_3_conv_RMSProp_1e-4.png') plot.plot_history(history)