tanthinhdt commited on
Commit
e0ba264
·
1 Parent(s): 56201f1

fix: builder

Browse files
Files changed (1) hide show
  1. how2sign-clips.py +27 -15
how2sign-clips.py CHANGED
@@ -69,14 +69,23 @@ class How2SignClips(datasets.GeneratorBasedBuilder):
69
  :return: Splits.
70
  """
71
  split_dict = {
72
- "train": datasets.Split.TRAIN,
73
- "test": datasets.Split.TEST,
74
- "val": datasets.Split.VALIDATION,
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
  return [
78
  datasets.SplitGenerator(
79
- name=name,
80
  gen_kwargs={
81
  "metadata_path": dl_manager.download(
82
  _URLS["meta"].format(split=split)
@@ -89,28 +98,31 @@ class How2SignClips(datasets.GeneratorBasedBuilder):
89
  )
90
  )
91
  ),
 
92
  },
93
  )
94
- for split, name in split_dict.items()
95
  ]
96
 
97
  def _generate_examples(
98
  self, metadata_path: str,
99
  video_dirs: list[str],
 
100
  ) -> tuple[int, dict]:
101
  """
102
  Generate examples from metadata.
103
  :param metadata_path: Path to metadata.
104
- :param visual_dir: Directory of visual data.
 
105
  :yield: Example.
106
  """
 
107
  dataset = datasets.load_dataset(
108
  "parquet",
109
  data_files=metadata_path,
110
  split="train",
111
  )
112
  for i, sample in enumerate(dataset):
113
- num_shards = len(video_dirs)
114
  shard_idx = sample["shard"]
115
  for video_dir in video_dirs:
116
  video_path = os.path.join(
@@ -118,14 +130,14 @@ class How2SignClips(datasets.GeneratorBasedBuilder):
118
  f"shard_{shard_idx:03d}_{num_shards:03d}",
119
  sample["id"] + ".mp4"
120
  )
121
- # if os.path.exists(video_path):
122
- yield i, {
123
- "id": sample["id"],
124
- "type": sample["type"],
125
- "view": sample["view"],
126
- "text": sample["text"],
127
- "video": self.__get_binary_data(video_path),
128
- }
129
 
130
  def __get_binary_data(self, path):
131
  with open(path, "rb") as f:
 
69
  :return: Splits.
70
  """
71
  split_dict = {
72
+ "train": {
73
+ "name": datasets.Split.TRAIN,
74
+ "num_shards": 32,
75
+ },
76
+ "test": {
77
+ "name": datasets.Split.TEST,
78
+ "num_shards": 3,
79
+ },
80
+ "val": {
81
+ "name": datasets.Split.VALIDATION,
82
+ "num_shards": 2,
83
+ },
84
  }
85
 
86
  return [
87
  datasets.SplitGenerator(
88
+ name=info["name"],
89
  gen_kwargs={
90
  "metadata_path": dl_manager.download(
91
  _URLS["meta"].format(split=split)
 
98
  )
99
  )
100
  ),
101
+ "num_shards": info["num_shards"],
102
  },
103
  )
104
+ for split, info in split_dict.items()
105
  ]
106
 
107
  def _generate_examples(
108
  self, metadata_path: str,
109
  video_dirs: list[str],
110
+ num_shards: int,
111
  ) -> tuple[int, dict]:
112
  """
113
  Generate examples from metadata.
114
  :param metadata_path: Path to metadata.
115
+ :param visual_dirs: Directories of videos.
116
+ :param num_shards: Number of shards.
117
  :yield: Example.
118
  """
119
+
120
  dataset = datasets.load_dataset(
121
  "parquet",
122
  data_files=metadata_path,
123
  split="train",
124
  )
125
  for i, sample in enumerate(dataset):
 
126
  shard_idx = sample["shard"]
127
  for video_dir in video_dirs:
128
  video_path = os.path.join(
 
130
  f"shard_{shard_idx:03d}_{num_shards:03d}",
131
  sample["id"] + ".mp4"
132
  )
133
+ if os.path.exists(video_path):
134
+ yield i, {
135
+ "id": sample["id"],
136
+ "type": sample["type"],
137
+ "view": sample["view"],
138
+ "text": sample["text"],
139
+ "video": self.__get_binary_data(video_path),
140
+ }
141
 
142
  def __get_binary_data(self, path):
143
  with open(path, "rb") as f: