| 219 | |
| 220 | |
| 221 | class MBenchWiRefMotion(torch.utils.data.Dataset): |
| 222 | def __init__(self, test_json_file_list, motion_mean_path, motion_std_path, null_context_path, use_global_orient=True, text_key='prompt_video_detailed', test_seq_len=100, **kwargs): |
| 223 | base_json_file_list = test_json_file_list |
| 224 | self.data_list = [] |
| 225 | for json_file in base_json_file_list: |
| 226 | data_list = json.load(open(json_file, 'r')) |
| 227 | self.data_list.extend(data_list) |
| 228 | |
| 229 | print(len(self.data_list), "tensors cached in metadata.") |
| 230 | motion_mean = np.load(motion_mean_path) |
| 231 | motion_std = np.load(motion_std_path) |
| 232 | self.motion_mean = torch.from_numpy(motion_mean).float() |
| 233 | self.motion_std = torch.from_numpy(motion_std).float() |
| 234 | self.null_context = torch.load(null_context_path, weights_only=True, map_location="cpu") # [226, 4096] |
| 235 | self.motion_dim = motion_mean.shape[-1] |
| 236 | self.use_global_orient = use_global_orient |
| 237 | text_key_mapping = { |
| 238 | 'video_text_annot': 'prompt_video_detailed', |
| 239 | 'motion_text_annot': 'prompt_motion_detailed' |
| 240 | } |
| 241 | text_key = text_key_mapping.get(text_key, text_key) |
| 242 | self.text_key = text_key |
| 243 | self.prompt_emb_key = f'{text_key}_wanvideot5_embed_path' |
| 244 | self.test_seq_len = test_seq_len |
| 245 | |
| 246 | def __getitem__(self, index): |
| 247 | data = self.data_list[index] |
| 248 | enable_m2m = False |
| 249 | if "motion_path" in data and data.get("use_ref_motion", False): |
| 250 | motion_path = data["motion_path"] |
| 251 | motion = torch.load(motion_path, weights_only=True, map_location="cpu") |
| 252 | if isinstance(motion, dict): |
| 253 | motion = motion["motion"] |
| 254 | # interpolate motion from 16 fps to 20 fps |
| 255 | original_frames = motion.shape[0] |
| 256 | target_frames = original_frames * 20 // 16 |
| 257 | # [original_frames, motion_dim] -> [target_frames, motion_dim] |
| 258 | motion = torch.nn.functional.interpolate(motion.unsqueeze(0).permute(0, 2, 1), size=target_frames, mode='linear', align_corners=True).squeeze(0).permute(1, 0) |
| 259 | enable_m2m = True |
| 260 | else: |
| 261 | motion = torch.zeros((self.test_seq_len, self.motion_dim)).float() |
| 262 | |
| 263 | motion_length = motion.shape[0] |
| 264 | motion_duration = motion_length / 20.0 # assuming 20 fps |
| 265 | |
| 266 | # normalize motion |
| 267 | data_dict = {} |
| 268 | motion = motion[:, :self.motion_dim] |
| 269 | motion = (motion - self.motion_mean) / self.motion_std |
| 270 | data_dict["motion"] = motion |
| 271 | data_dict["motion_length"] = motion_length |
| 272 | motion_dim_mask = torch.ones(self.motion_dim) |
| 273 | |
| 274 | joint_num = 22 |
| 275 | # ref motion |
| 276 | ref_motion = motion.clone() |
| 277 | |
| 278 | # only use the local ref motion |
nothing calls this directly
no outgoing calls
no test coverage detected