示例#1
0
    def load_model(self, directory, epoch=None):
        names = self.get_model_names()
        model_file = 'model.pth.tar-' + str(
            epoch) if epoch else 'model-best.pth.tar'

        for name in names:
            model_path = osp.join(directory, name, model_file)

            if not osp.exists(model_path):
                raise FileNotFoundError(
                    'Model not found at "{}"'.format(model_path))

            checkpoint = load_checkpoint(model_path)
            state_dict = checkpoint['state_dict']
            epoch = checkpoint['epoch']

            print('Loading weights to {} '
                  'from "{}" (epoch = {})'.format(name, model_path, epoch))
            self._models[name].load_state_dict(state_dict)
示例#2
0
    def load_model(self, directory, epoch=None):
        model_file = 'model.pth.tar-' + str(
            epoch) if epoch else 'model-best.pth.tar'

        target = self.cfg.DATASET.TARGET_DOMAINS[0]

        for i, domain in enumerate(self.cfg.DATASET.SOURCE_DOMAINS):
            task = domain + '2' + target
            model_path = osp.join(directory, task, 'model', model_file)

            if not osp.exists(model_path):
                raise FileNotFoundError(
                    'Model not found at "{}"'.format(model_path))

            checkpoint = load_checkpoint(model_path)
            state_dict = checkpoint['state_dict']
            epoch = checkpoint['epoch']

            print('Loading weights to the model of {} '
                  'from "{}" (epoch = {})'.format(domain, model_path, epoch))
            self.models[i].load_state_dict(state_dict)