Ejemplo n.º 1
0
 def load_loss(self, loss):
     """
     Initialize PyTorch loss function
     :param loss: class name of loss
     :return: initialized loss
     """
     Loss = import_class(loss)
     loss = Loss()
     self.logger.print_log(f'Loss: {Loss.__name__} initialized')
     return loss
Ejemplo n.º 2
0
 def load_sampler(self, sampler, **sampler_args):
     """
     Initialize data sampler
     :param sampler: class name of sampler
     :param sampler_args: arguments for sampler
     :return: initialized sampler
     """
     Sampler = import_class(sampler)
     sampler = Sampler(**sampler_args)
     self.logger.print_log(f'Sampler: {Sampler.__name__} initialized')
     return sampler
Ejemplo n.º 3
0
 def load_feeder(self, feeder, **feeder_args):
     """
     Initialize data feeder
     :param feeder: class name of feeder
     :param feeder_args: arguments for feeder
     :return: initialized feeder
     """
     Feeder = import_class(feeder)
     feeder = Feeder(**feeder_args)
     self.logger.print_log(f'Feeder: {Feeder.__name__} initialized')
     return feeder
Ejemplo n.º 4
0
 def load_scheduler(self, scheduler, optimizer, **scheduler_args):
     """
     Initialize PyTorch scheduler
     :param scheduler: class name of scheduler
     :param optimizer: initialized optimizer
     :param scheduler_args: arguments for scheduler
     :return: initialized scheduler
     """
     Scheduler = import_class(scheduler)
     scheduler = Scheduler(optimizer, **scheduler_args)
     self.logger.print_log(f'Scheduler: {Scheduler.__name__} initialized')
     return scheduler
Ejemplo n.º 5
0
 def load_optimizer(self, optimizer, model, **optimizer_args):
     """
     Initialize PyTorch optimizer for model training
     :param optimizer: class name of optimizer
     :param model: model to optimize
     :param optimizer_args: arguments for optimizer
     :return: initialized optimizer
     """
     Optimizer = import_class(optimizer)
     optimizer = Optimizer(model.parameters(), **optimizer_args)
     self.logger.print_log(f'Optimizer: {Optimizer.__name__} initialized')
     return optimizer
Ejemplo n.º 6
0
 def load_model(self, model, **model_args):
     """
     Load PyTorch model
     :param model: class name of model
     :param model_args: arguments for model
     :return: initialized model
     """
     Model = import_class(model)
     model = Model(**model_args)
     self.model_text += '\n\n' + str(model)
     self.logger.print_log(f'Model: {Model.__name__} initialized')
     return model