Ejemplo n.º 1
0
 def __init__(self,
              model_factory,
              dataset,
              params,
              dataset_cfg,
              experiment_cfg,
              restore_checkpoint,
              logger=None):
     items = model_factory(params)
     self.logger = logger if logger else Logger.get()
     self.model = items['model']
     # self.optimizer = items['optimizer']
     self.criterion = items['criterion']
     self.metrics = items['metrics']
     # restore model from checkpoint
     checkpoint = Checkpoint(
         checkpoint_dir=experiment_cfg.experiment_dir(),
         filename=experiment_cfg.checkpoint_filename(),
         best_checkpoint=experiment_cfg.best_checkpoint(),
         latest_checkpoint=experiment_cfg.latest_checkpoint(),
         logger=self.logger)
     status = checkpoint.restore(self.model, None, restore_checkpoint)
     assert status, "Restore model from the checkpoint: {}, failed".format(
         restore_checkpoint)
     self.dataset = dataset
     self.metrics_file = experiment_cfg.metrics_file(
         restore_checkpoint, self.dataset.dataset_name)
Ejemplo n.º 2
0
 def __init__(self,
              model_factory,
              trainloader,
              valloader,
              params,
              dataset_cfg,
              experiment_cfg,
              best_metric_recorder,
              restore_checkpoint=None,
              logger=None):
     logger = logger if logger else Logger.get()
     items = model_factory(params)
     self.model = items['model']
     self.optimizer = items['optimizer']
     self.criterion = items['criterion']
     self.metrics = items['metrics']
     self.best_metric_recorder = best_metric_recorder
     self.trainloader = trainloader
     self.valloader = valloader
     self.num_epochs = params.num_epochs
     self.running_avg_steps = params.running_avg_steps
     self.checkpoint = Checkpoint(
         checkpoint_dir=experiment_cfg.experiment_dir(),
         filename=experiment_cfg.checkpoint_filename(),
         best_checkpoint=experiment_cfg.best_checkpoint(),
         latest_checkpoint=experiment_cfg.latest_checkpoint(),
         logger=logger)
     self.best_metrics_file = experiment_cfg.best_metrics_file(
         dataset_cfg.val_name())
     self.latest_metrics_file = experiment_cfg.latest_metrics_file(
         dataset_cfg.val_name())
     self.restore_checkpoint = restore_checkpoint
     self.logger = logger