MCPcopy Create free account
hub / github.com/MotrixLab/insactor / TextMotionDataset

Class TextMotionDataset

diffplanner/datasets/text_motion_dataset.py:20–77  ·  view source on GitHub ↗

TextMotion dataset. Args: text_dir (str): Path to the directory containing the text files.

Source from the content-addressed store, hash-verified

18
19@DATASETS.register_module()
20class TextMotionDataset(BaseMotionDataset):
21 """TextMotion dataset.
22
23 Args:
24 text_dir (str): Path to the directory containing the text files.
25 """
26 def __init__(self,
27 data_prefix: str,
28 pipeline: list,
29 dataset_name: Optional[Union[str, None]] = None,
30 fixed_length: Optional[Union[int, None]] = None,
31 ann_file: Optional[Union[str, None]] = None,
32 motion_dir: Optional[Union[str, None]] = None,
33 text_dir: Optional[Union[str, None]] = None,
34 token_dir: Optional[Union[str, None]] = None,
35 eval_cfg: Optional[Union[dict, None]] = None,
36 test_mode: Optional[bool] = False):
37 self.text_dir = os.path.join(data_prefix, 'datasets', dataset_name, text_dir)
38 if token_dir is not None:
39 self.token_dir = os.path.join(data_prefix, 'datasets', dataset_name, token_dir)
40 else:
41 self.token_dir = None
42 super(TextMotionDataset, self).__init__(
43 data_prefix=data_prefix,
44 pipeline=pipeline,
45 dataset_name=dataset_name,
46 fixed_length=fixed_length,
47 ann_file=ann_file,
48 motion_dir=motion_dir,
49 eval_cfg=eval_cfg,
50 test_mode=test_mode)
51
52 def load_anno(self, name):
53 results = super().load_anno(name)
54 text_path = os.path.join(self.text_dir, name + '.txt')
55 text_data = []
56 for line in open(text_path, 'r'):
57 text_data.append(line.strip())
58 results['text'] = text_data
59 if self.token_dir is not None:
60 token_path = os.path.join(self.token_dir, name + '.txt')
61 token_data = []
62 for line in open(token_path, 'r'):
63 token_data.append(line.strip())
64 results['token'] = token_data
65 return results
66
67 def prepare_data(self, idx: int):
68 """"Prepare raw data for the f'{idx'}-th data."""
69 results = copy.deepcopy(self.data_infos[idx])
70 text_list = results['text']
71 idx = np.random.randint(0, len(text_list))
72 results['text'] = text_list[idx]
73 if 'token' in results.keys():
74 results['token'] = results['token'][idx]
75 results['dataset_name'] = self.dataset_name
76 results['sample_idx'] = idx
77 return self.pipeline(results)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected