MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / WanMotionTensorDatasetWiRefMotion

Class WanMotionTensorDatasetWiRefMotion

datasets/video_datasets.py:8–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class WanMotionTensorDatasetWiRefMotion(torch.utils.data.Dataset):
9 def __init__(self, train_json_file_list, test_json_file_list, motion_mean_path, motion_std_path, min_motion_length, max_motion_length, null_context_path, uncond_prob=0.5, is_test=False, use_global_orient=True, text_key='video_text_annot', duplicate_meta=None, t2m_prob_low_quality=0.4, t2m_prob_default=0.8, **kwargs):
10 self.data_list = self._load_data_list(
11 train_json_file_list=train_json_file_list,
12 test_json_file_list=test_json_file_list,
13 duplicate_meta=duplicate_meta,
14 is_test=is_test,
15 )
16 print(len(self.data_list), "tensors cached in metadata.")
17
18 motion_mean = np.load(motion_mean_path)
19 motion_std = np.load(motion_std_path)
20
21 self.motion_mean = torch.from_numpy(motion_mean).float()
22 self.motion_std = torch.from_numpy(motion_std).float()
23 self.motion_dim = motion_mean.shape[-1]
24 self.min_motion_length = min_motion_length
25 self.max_motion_length = max_motion_length
26 self.uncond_prob = uncond_prob
27 self.null_context = torch.load(null_context_path, weights_only=True, map_location="cpu") # [226, 4096]
28 self.is_test = is_test
29 self.use_global_orient = use_global_orient
30 self.text_key = text_key
31 self.prompt_emb_key = f'{text_key}_wanvideot5_embed_path'
32 # motion31/mogen_db captions are noisier, so use lower T2M probability by default.
33 self.t2m_prob_low_quality = t2m_prob_low_quality
34 # Other datasets default to a higher T2M probability.
35 self.t2m_prob_default = t2m_prob_default
36 total_samples = len(self.data_list)
37 missing_prompt = 0
38 for sample in self.data_list:
39 prompt_path = sample.get(self.prompt_emb_key)
40 if prompt_path is None or not os.path.exists(prompt_path):
41 missing_prompt += 1
42 print(
43 f'[{self.__class__.__name__}] prompt embeddings with key "{self.prompt_emb_key}": '
44 f'{total_samples - missing_prompt}/{total_samples} available'
45 )
46
47 def __getitem__(self, index):
48 sample_index, data, motion, motion_path = self._fetch_motion_sample(index)
49 motion_length = motion.shape[0]
50
51 normalized_motion = self._normalize_motion_tensor(motion)
52
53 data_dict = {
54 "motion": normalized_motion,
55 "motion_length": motion_length,
56 }
57 motion_dim_mask = torch.ones(self.motion_dim)
58
59 ref_motion_dict, motion_dim_mask, attend_to_text_mask = self._prepare_ref_motion(
60 data=data,
61 motion=normalized_motion,
62 motion_dim_mask=motion_dim_mask,
63 motion_path=motion_path,
64 )
65 data_dict.update(ref_motion_dict)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected