Delete how2sign-clips.py
Browse files- how2sign-clips.py +0 -164
how2sign-clips.py
DELETED
|
@@ -1,164 +0,0 @@
|
|
| 1 |
-
# Copyright 2023 Thinh T. Duong
|
| 2 |
-
import os
|
| 3 |
-
import datasets
|
| 4 |
-
from glob import glob
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
logger = datasets.logging.get_logger(__name__)
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
_CITATION = """
|
| 11 |
-
|
| 12 |
-
"""
|
| 13 |
-
_DESCRIPTION = """
|
| 14 |
-
"""
|
| 15 |
-
_HOMEPAGE = "https://how2sign.github.io/index.html"
|
| 16 |
-
_REPO_URL = "https://huggingface.co/datasets/VieSignLang/how2sign-clips/resolve/main"
|
| 17 |
-
_URLS = {
|
| 18 |
-
"meta": f"{_REPO_URL}/metadata/" + "sharded_how2sign_realigned_{split}.parquet",
|
| 19 |
-
"video": f"{_REPO_URL}/videos/" + "{type}/{split}/*/*.zip",
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
class How2SignClipsConfig(datasets.BuilderConfig):
|
| 24 |
-
"""How2Sign configuration."""
|
| 25 |
-
|
| 26 |
-
def __init__(self, name, **kwargs):
|
| 27 |
-
"""
|
| 28 |
-
:param name: Name of subset.
|
| 29 |
-
:param kwargs: Arguments.
|
| 30 |
-
"""
|
| 31 |
-
super(How2SignClipsConfig, self).__init__(
|
| 32 |
-
name=name,
|
| 33 |
-
version=datasets.Version("1.0.0"),
|
| 34 |
-
description=_DESCRIPTION,
|
| 35 |
-
**kwargs,
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
class How2SignClips(datasets.GeneratorBasedBuilder):
|
| 40 |
-
"""How2Sign dataset."""
|
| 41 |
-
BUILDER_CONFIGS = [
|
| 42 |
-
How2SignClipsConfig(name="rgb"),
|
| 43 |
-
# How2SignClipsConfig(name="keypoints"),
|
| 44 |
-
]
|
| 45 |
-
DEFAULT_CONFIG_NAME = "rgb"
|
| 46 |
-
|
| 47 |
-
def _info(self) -> datasets.DatasetInfo:
|
| 48 |
-
features = datasets.Features({
|
| 49 |
-
"VIDEO_ID": datasets.Value("string"),
|
| 50 |
-
"VIDEO_NAME": datasets.Value("string"),
|
| 51 |
-
"SENTENCE_ID": datasets.Value("string"),
|
| 52 |
-
"SENTENCE_NAME": datasets.Value("string"),
|
| 53 |
-
"START_REALIGNED": datasets.Value("float64"),
|
| 54 |
-
"END_REALIGNED": datasets.Value("float64"),
|
| 55 |
-
"SENTENCE": datasets.Value("string"),
|
| 56 |
-
"VIDEO": datasets.Value("large_binary"),
|
| 57 |
-
})
|
| 58 |
-
# features = datasets.Features({
|
| 59 |
-
# "id": datasets.Value("string"),
|
| 60 |
-
# "type": datasets.Value("string"),
|
| 61 |
-
# "view": datasets.Value("string"),
|
| 62 |
-
# "text": datasets.Value("string"),
|
| 63 |
-
# "video": datasets.Value("large_binary"),
|
| 64 |
-
# })
|
| 65 |
-
|
| 66 |
-
return datasets.DatasetInfo(
|
| 67 |
-
description=_DESCRIPTION,
|
| 68 |
-
features=features,
|
| 69 |
-
homepage=_HOMEPAGE,
|
| 70 |
-
citation=_CITATION,
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
def _split_generators(
|
| 74 |
-
self, dl_manager: datasets.DownloadManager
|
| 75 |
-
) -> list[datasets.SplitGenerator]:
|
| 76 |
-
"""
|
| 77 |
-
Get splits.
|
| 78 |
-
:param dl_manager: Download manager.
|
| 79 |
-
:return: Splits.
|
| 80 |
-
"""
|
| 81 |
-
split_dict = {
|
| 82 |
-
"train": {
|
| 83 |
-
"name": datasets.Split.TRAIN,
|
| 84 |
-
"num_shards": 32,
|
| 85 |
-
},
|
| 86 |
-
"test": {
|
| 87 |
-
"name": datasets.Split.TEST,
|
| 88 |
-
"num_shards": 3,
|
| 89 |
-
},
|
| 90 |
-
"val": {
|
| 91 |
-
"name": datasets.Split.VALIDATION,
|
| 92 |
-
"num_shards": 2,
|
| 93 |
-
},
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
return [
|
| 97 |
-
datasets.SplitGenerator(
|
| 98 |
-
name=info["name"],
|
| 99 |
-
gen_kwargs={
|
| 100 |
-
"metadata_path": dl_manager.download(
|
| 101 |
-
_URLS["meta"].format(split=split)
|
| 102 |
-
),
|
| 103 |
-
"video_dirs": dl_manager.download_and_extract(
|
| 104 |
-
glob(
|
| 105 |
-
_URLS["video"].format(
|
| 106 |
-
type=self.config.name,
|
| 107 |
-
split=split
|
| 108 |
-
)
|
| 109 |
-
)
|
| 110 |
-
),
|
| 111 |
-
"num_shards": info["num_shards"],
|
| 112 |
-
},
|
| 113 |
-
)
|
| 114 |
-
for split, info in split_dict.items()
|
| 115 |
-
]
|
| 116 |
-
|
| 117 |
-
def _generate_examples(
|
| 118 |
-
self, metadata_path: str,
|
| 119 |
-
video_dirs: list[str],
|
| 120 |
-
num_shards: int,
|
| 121 |
-
) -> tuple[int, dict]:
|
| 122 |
-
"""
|
| 123 |
-
Generate examples from metadata.
|
| 124 |
-
:param metadata_path: Path to metadata.
|
| 125 |
-
:param visual_dirs: Directories of videos.
|
| 126 |
-
:param num_shards: Number of shards.
|
| 127 |
-
:yield: Example.
|
| 128 |
-
"""
|
| 129 |
-
dataset = datasets.load_dataset(
|
| 130 |
-
"parquet",
|
| 131 |
-
data_files=metadata_path,
|
| 132 |
-
split="train",
|
| 133 |
-
)
|
| 134 |
-
for i, sample in enumerate(dataset):
|
| 135 |
-
shard_idx = sample["shard"]
|
| 136 |
-
for video_dir in video_dirs:
|
| 137 |
-
video_path = os.path.join(
|
| 138 |
-
video_dir,
|
| 139 |
-
f"shard_{shard_idx:03d}_{num_shards:03d}",
|
| 140 |
-
sample["SENTENCE_NAME"] + ".mp4",
|
| 141 |
-
# sample["id"] + ".mp4",
|
| 142 |
-
)
|
| 143 |
-
if os.path.exists(video_path):
|
| 144 |
-
yield i, {
|
| 145 |
-
"VIDEO_ID": sample["VIDEO_ID"],
|
| 146 |
-
"VIDEO_NAME": sample["VIDEO_NAME"],
|
| 147 |
-
"SENTENCE_ID": sample["SENTENCE_ID"],
|
| 148 |
-
"SENTENCE_NAME": sample["SENTENCE_NAME"],
|
| 149 |
-
"START_REALIGNED": sample["START_REALIGNED"],
|
| 150 |
-
"END_REALIGNED": sample["END_REALIGNED"],
|
| 151 |
-
"SENTENCE": sample["SENTENCE"],
|
| 152 |
-
"VIDEO": self.__get_binary_data(video_path),
|
| 153 |
-
}
|
| 154 |
-
# yield i, {
|
| 155 |
-
# "id": sample["id"],
|
| 156 |
-
# "type": sample["type"],
|
| 157 |
-
# "view": sample["view"],
|
| 158 |
-
# "text": sample["text"],
|
| 159 |
-
# "video": self.__get_binary_data(video_path),
|
| 160 |
-
# }
|
| 161 |
-
|
| 162 |
-
def __get_binary_data(self, path):
|
| 163 |
-
with open(path, "rb") as f:
|
| 164 |
-
return f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|