MCPcopy Create free account
hub / github.com/MotrixLab/ADHMR / validate

Method validate

ADHMR/lib/runners/inference.py:74–187  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

72
73
74 def validate(self):
75 args, config = self.args, self.config
76
77 rank = torch.distributed.get_rank()
78 model, model_cond, __, __, __, __, __, __, __, __, __ = get_model(config, is_train=False, resume = True, resume_path = config.training.scorenet.test_path)
79 model = nn.parallel.DistributedDataParallel(model, device_ids=[args.device], output_device=args.local_rank)
80 model_cond = nn.parallel.DistributedDataParallel(model_cond, device_ids=[args.device], output_device=args.local_rank)
81 model_score, model_score_cond, __, __, __, __, epoch, step, __ = get_model_score(config, is_train=False, resume = True, resume_path = self.config.sampling.ckpt)
82 model_score = nn.parallel.DistributedDataParallel(model_score, device_ids=[args.device], output_device=args.local_rank)
83 model_score_cond = nn.parallel.DistributedDataParallel(model_score_cond, device_ids=[args.device], output_device=args.local_rank)
84 state = dict(model = model, model_cond = model_cond, model_score = model_score, epoch = epoch, model_score_cond = model_score_cond)
85
86 KST = datetime.timezone(datetime.timedelta(hours=8))
87 if config.inference.input_type == 'video':
88 dname = config.inference.input_name
89 else:
90 dname = 'image'
91 config.inference.out_dir = os.path.join(config.inference.out_dir,str(datetime.datetime.now(tz=KST))[5:-16]+dname)
92
93 list_name = [config.inference.input_type,'mesh']
94 for name in list_name:
95 path = os.path.join(config.inference.out_dir,name)
96 if os.path.exists(path) and rank == 0:
97 shutil.rmtree(path)
98 os.makedirs(path,exist_ok=True)
99
100 img_path_list, img_dir, fps = get_image_path(config)
101
102
103 virtualpose_name = 'VirtualPose'
104 det_update_config(f'{virtualpose_name}/configs/images/images_inference.yaml')
105
106 cur_path = config.inference.det_dir
107 img_dir = img_dir
108
109 det_model = eval('det_models.multi_person_posenet.get_multi_person_pose_net')(det_cfg, is_train=False)
110 with torch.no_grad():
111 det_model = torch.nn.DataParallel(det_model,device_ids=[rank])
112
113 pretrained_file = osp.join(cur_path, f'{virtualpose_name}', det_cfg.NETWORK.PRETRAINED)
114 state_dict = torch.load(pretrained_file)
115 new_state_dict = {k:v for k, v in state_dict.items() if 'backbone.pose_branch.' not in k}
116 det_model.module.load_state_dict(new_state_dict, strict = False)
117 pretrained_file = osp.join(cur_path, f'{virtualpose_name}', det_cfg.NETWORK.PRETRAINED_BACKBONE)
118 det_model = load_backbone_validate(det_model, pretrained_file)
119
120 # prepare detection dataset
121 infer_dataset = det_dataset.images(
122 det_cfg, img_dir, focal_length=1700,
123 transform=transforms.Compose([
124 transforms.ToTensor(),
125 transforms.Normalize(
126 mean=[0.485, 0.456, 0.406],
127 std=[0.229, 0.224, 0.225]),
128 ]))
129 infer_loader = torch.utils.data.DataLoader(
130 infer_dataset,
131 batch_size=config.inference.det_bs,

Callers

nothing calls this directly

Calls 12

sampleMethod · 0.95
DemoDatasetClass · 0.90
get_modelFunction · 0.85
get_model_scoreFunction · 0.85
get_image_pathFunction · 0.85
output2original_scaleFunction · 0.85
infoMethod · 0.80
loadMethod · 0.45
itemsMethod · 0.45
load_state_dictMethod · 0.45
keysMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected