()
| 77 | |
| 78 | |
| 79 | def main(): |
| 80 | args = parse_args() |
| 81 | |
| 82 | cfg = mmcv.Config.fromfile(args.config) |
| 83 | # set cudnn_benchmark |
| 84 | if cfg.get('cudnn_benchmark', False): |
| 85 | torch.backends.cudnn.benchmark = True |
| 86 | cfg.data.test.test_mode = True |
| 87 | |
| 88 | # build the model and load checkpoint |
| 89 | model = build_architecture(cfg.model) |
| 90 | load_checkpoint(model, args.checkpoint, map_location='cpu') |
| 91 | |
| 92 | if args.device == 'cpu': |
| 93 | model = model.cpu() |
| 94 | else: |
| 95 | model = MMDataParallel(model, device_ids=[0]) |
| 96 | model.eval() |
| 97 | |
| 98 | dataset_name = cfg.data.test.dataset_name |
| 99 | assert dataset_name in ["human_ml3d", "inter_human"] |
| 100 | assert len(args.motion_length) == len(args.text) |
| 101 | max_length = max(args.motion_length) |
| 102 | if dataset_name == "human_ml3d": |
| 103 | input_dim = 263 |
| 104 | assert max_length >= 16 and max_length <= 196 |
| 105 | elif dataset_name == "inter_human": |
| 106 | input_dim = 524 |
| 107 | assert max_length >= 16 and max_length <= 300 |
| 108 | mean_path = os.path.join("data", "datasets", dataset_name, "mean.npy") |
| 109 | std_path = os.path.join("data", "datasets", dataset_name, "std.npy") |
| 110 | mean = np.load(mean_path) |
| 111 | std = np.load(std_path) |
| 112 | |
| 113 | device = args.device |
| 114 | num_intervals = len(args.text) |
| 115 | motion = torch.zeros(num_intervals, max_length, input_dim).to(device) |
| 116 | motion_mask = torch.zeros(num_intervals, max_length).to(device) |
| 117 | for i in range(num_intervals): |
| 118 | motion_mask[i, :args.motion_length[i]] = 1 |
| 119 | motion_length = torch.Tensor(args.motion_length).long().to(device) |
| 120 | model = model.to(device) |
| 121 | metas = [] |
| 122 | for t in args.text: |
| 123 | metas.append({'text': t}) |
| 124 | input = { |
| 125 | 'motion': motion, |
| 126 | 'motion_mask': motion_mask, |
| 127 | 'motion_length': motion_length, |
| 128 | 'num_intervals': num_intervals, |
| 129 | 'motion_metas': metas, |
| 130 | } |
| 131 | |
| 132 | all_pred_motion = [] |
| 133 | with torch.no_grad(): |
| 134 | input['inference_kwargs'] = {} |
| 135 | output = model(**input) |
| 136 | for i in range(num_intervals): |
no test coverage detected