def setup_model_optimizer_lossfn(self):
    odim = (self.base_feature_extractor.module.output_feature_sz if self.use_multi_gpu else self.base_feature_extractor.output_feature_sz)
    mi_model = build_model(opts=self.opts, diag_classes=self.diag_classes, base_feature_odim=odim)
    if (self.resume is not None):
        (resume_ep, resume_model_state, resume_optim_state, resume_perf) = load_checkpoint(checkpoint_dir=self.opts.checkpoint, device=self.device)
        self.start_epoch = resume_ep
        self.best_acc = resume_perf
        self.mi_model.load_state_dict(resume_model_state)
        self.optimizer.load_state_dict(resume_optim_state)
        for state in self.optimizer.state.values():
            for (k, v) in state.items():
                if isinstance(v, torch.Tensor):
                    state[k] = v.to(device=self.device)
        print_log_message('Resuming from checkpoint saved at {}th epoch'.format(self.start_epoch))
    mi_model = mi_model.to(device=self.device)
    if self.use_multi_gpu:
        mi_model = torch.nn.DataParallel(mi_model)
    self.mi_model = mi_model
    criteria = build_criteria(opts=self.opts, class_weights=self.class_weights.float())
    self.criteria = criteria.to(device=self.device)
    self.optimizer = build_optimizer(model=self.mi_model, opts=self.opts)
def setup_model_optimizer_lossfn(self):
    odim = (self.base_feature_extractor.module.output_feature_sz if self.use_multi_gpu else self.base_feature_extractor.output_feature_sz)
    mi_model = build_model(opts=self.opts, diag_classes=self.diag_classes, base_feature_odim=odim)
    if (self.resume is not None):
        (resume_ep, resume_model_state, resume_optim_state, resume_perf) = load_checkpoint(checkpoint_dir=self.opts.checkpoint, device=self.device)
        self.start_epoch = resume_ep
        self.best_acc = resume_perf
        self.mi_model.load_state_dict(resume_model_state)
        self.optimizer.load_state_dict(resume_optim_state)
        for state in self.optimizer.state.values():
            for (k, v) in state.items():
                if isinstance(v, torch.Tensor):
                    state[k] = v.to(device=self.device)
        print_log_message('Resuming from checkpoint saved at {}th epoch'.format(self.start_epoch))
    mi_model = mi_model.to(device=self.device)
    if self.use_multi_gpu:
        mi_model = torch.nn.DataParallel(mi_model)
    self.mi_model = mi_model
    criteria = build_criteria(opts=self.opts, class_weights=self.class_weights.float())
    self.criteria = criteria.to(device=self.device)
    self.optimizer = build_optimizer(model=self.mi_model, opts=self.opts)