def load_checkpoints(config_path, checkpoint_path, device='cuda'): with open(config_path) as f: config = yaml.load(f) generator = OcclusionAwareGenerator( **config['model_params']['generator_params'], **config['model_params']['common_params']) generator.to(device) kp_detector = KPDetector(**config['model_params']['kp_detector_params'], **config['model_params']['common_params']) kp_detector.to(device) checkpoint = torch.load(checkpoint_path, map_location=device) generator.load_state_dict(checkpoint['generator']) kp_detector.load_state_dict(checkpoint['kp_detector']) generator = DataParallelWithCallback(generator) kp_detector = DataParallelWithCallback(kp_detector) generator.eval() kp_detector.eval() return generator, kp_detector
def load_checkpoints(config_path, checkpoint_path, device="cuda"): with open(config_path) as f: config = yaml.load(f, Loader=yaml.FullLoader) generator = OcclusionAwareGenerator( **config["model_params"]["generator_params"], **config["model_params"]["common_params"], ) generator.to(device) kp_detector = KPDetector( **config["model_params"]["kp_detector_params"], **config["model_params"]["common_params"], ) kp_detector.to(device) checkpoint = torch.load(checkpoint_path, map_location=device) generator.load_state_dict(checkpoint["generator"]) kp_detector.load_state_dict(checkpoint["kp_detector"]) generator = DataParallelWithCallback(generator) kp_detector = DataParallelWithCallback(kp_detector) generator.eval() kp_detector.eval() return generator, kp_detector
def load_generator_and_keypoint_detector(self): config = self.load_config() generator = OcclusionAwareGenerator( **config['model_params']['generator_params'], **config['model_params']['common_params']) generator.to(self.device) kp_detector = KPDetector( **config['model_params']['kp_detector_params'], **config['model_params']['common_params']) kp_detector.to(self.device) checkpoints = self.load_checkpoints() generator.load_state_dict(checkpoints['generator']) kp_detector.load_state_dict(checkpoints['kp_detector']) generator.eval() kp_detector.eval() return generator, kp_detector
def load_checkpoints(self): with open(self.config_path) as f: config = yaml.load(f) generator = OcclusionAwareGenerator(**config['model_params']['generator_params'], **config['model_params']['common_params']) generator.to(self.device) kp_detector = KPDetector(**config['model_params']['kp_detector_params'], **config['model_params']['common_params']) kp_detector.to(self.device) checkpoint = torch.load(self.checkpoint_path, map_location=self.device) generator.load_state_dict(checkpoint['generator']) kp_detector.load_state_dict(checkpoint['kp_detector']) generator.eval() kp_detector.eval() return generator, kp_detector
# Declare a discriminator discriminator = MultiScaleDiscriminator( **config['model_params']['discriminator_params'], **config['model_params']['common_params']) if torch.cuda.is_available(): discriminator.to(opt.device_ids[0]) if opt.verbose: print(discriminator) # Declare a key point detector kp_detector = KPDetector(**config['model_params']['kp_detector_params'], **config['model_params']['common_params']) if torch.cuda.is_available(): kp_detector.to(opt.device_ids[0]) # Print network details if using --verbose flag if opt.verbose: print(kp_detector) # Read in dataset details, defined in *.yaml config file, "dataset_params" section # Refer to ./config/vox-256.yaml for details # 数据预处理在此步骤完成,并读取进 dataset 变量中 dataset = FramesDataset(is_train=(opt.mode == 'train'), **config['dataset_params']) print("Dataset size: {}, repeat number: {}".format( len(dataset), config['train_params']['num_repeats'])) # Create the logging direction if not os.path.exists(log_dir):