def train(self, n_iterations):
print("Training network...")
# Recover losses from previous run
if (self.option == 'continue'):
with open("{0}_{1}_loss.json".format(self.root, self.depth), 'r') as f:
losses = json.load(f)
else:
losses = []
self.checkpointer = ModelCheckpoint(filepath="{0}_{1}_weights.hdf5".format(self.root, self.depth), verbose=1, save_best_only=True)
self.history = LossHistory(self.root, self.depth, losses, {'name': '{0}_{1}'.format(self.root, self.depth), 'init_t': time.asctime()})
self.reduce_lr = LearningRateScheduler(self.learning_rate)
self.metrics = self.model.fit_generator(self.training_generator(), self.batchs_per_epoch_training, epochs=n_iterations,
callbacks=[self.checkpointer, self.history, self.reduce_lr], validation_data=self.validation_generator(), validation_steps=self.batchs_per_epoch_validation)
self.history.finalize()
评论列表
文章目录