def train(self):
    if (len(self.gpus) >= 2):
        self._forward_once_for_flops(self.model)
    if (self.train_dir is not None):
        with open(os.path.join(self.train_dir, 'model.log'), 'w') as f:
            f.write(str(self.model))
    for epoch in range((self.last_epoch + 1), (self.epochs + 1)):
        self.epoch = epoch
        self.on_epoch_start(epoch)
        if (epoch < self.warmup_epochs):
            _warmup_update_lr(self.optimizer, epoch, self.learning_rate, self.warmup_epochs)
        elif ((self.scheduler is not None) and (epoch != 1)):
            self.scheduler.step()
        self.logger.info('epoch %d lr %e', epoch, self.optimizer.param_groups[0]['lr'])
        (train_acc, train_obj) = self.train_epoch(self.train_queue, self.parallel_model, self._criterion, self.optimizer, self.device, epoch)
        self.logger.info('train_acc %f ; train_obj %f', train_acc, train_obj)
        if (self.save_every and ((epoch % self.save_every) == 0)):
            path = os.path.join(self.train_dir, str(epoch))
            self.save(path)
        if ((epoch % self.eval_every) == 0):
            (valid_acc, valid_obj, valid_perfs) = self.infer_epoch(self.valid_queue, self.parallel_model, self._criterion, self.device)
            self.logger.info('valid_acc %f ; valid_obj %f ; valid performances: %s', valid_acc, valid_obj, '; '.join(['{}: {:.3f}'.format(n, v) for (n, v) in valid_perfs.items()]))
        self.on_epoch_end(epoch)
    self.save(os.path.join(self.train_dir, 'final'))
def train(self):
    if (len(self.gpus) >= 2):
        self._forward_once_for_flops(self.model)
    if (self.train_dir is not None):
        with open(os.path.join(self.train_dir, 'model.log'), 'w') as f:
            f.write(str(self.model))
    for epoch in range((self.last_epoch + 1), (self.epochs + 1)):
        self.epoch = epoch
        self.on_epoch_start(epoch)
        if (epoch < self.warmup_epochs):
            _warmup_update_lr(self.optimizer, epoch, self.learning_rate, self.warmup_epochs)
        elif ((self.scheduler is not None) and (epoch != 1)):
            self.scheduler.step()
        self.logger.info('epoch %d lr %e', epoch, self.optimizer.param_groups[0]['lr'])
        (train_acc, train_obj) = self.train_epoch(self.train_queue, self.parallel_model, self._criterion, self.optimizer, self.device, epoch)
        self.logger.info('train_acc %f ; train_obj %f', train_acc, train_obj)
        if (self.save_every and ((epoch % self.save_every) == 0)):
            path = os.path.join(self.train_dir, str(epoch))
            self.save(path)
        if ((epoch % self.eval_every) == 0):
            (valid_acc, valid_obj, valid_perfs) = self.infer_epoch(self.valid_queue, self.parallel_model, self._criterion, self.device)
            self.logger.info('valid_acc %f ; valid_obj %f ; valid performances: %s', valid_acc, valid_obj, '; '.join(['{}: {:.3f}'.format(n, v) for (n, v) in valid_perfs.items()]))
        self.on_epoch_end(epoch)
    self.save(os.path.join(self.train_dir, 'final'))