holylovenia
commited on
Commit
•
386b31f
1
Parent(s):
766b71c
Upload fsl_105.py with huggingface_hub
Browse files- fsl_105.py +194 -0
fsl_105.py
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path, PureWindowsPath
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
try:
|
6 |
+
import cv2
|
7 |
+
except:
|
8 |
+
print("Install the `cv2` package to use.")
|
9 |
+
import datasets
|
10 |
+
import pandas as pd
|
11 |
+
|
12 |
+
from seacrowd.utils import schemas
|
13 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
14 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
15 |
+
|
16 |
+
_CITATION = """\
|
17 |
+
@article{tupal4476867fsl105,
|
18 |
+
title={FSL105: The Video Filipino Sign Language Sign Database of Introductory 105 FSL Signs},
|
19 |
+
author={Tupal, Isaiah Jassen Lizaso and Melvin, Cabatuan K},
|
20 |
+
journal={Available at SSRN 4476867}
|
21 |
+
}
|
22 |
+
"""
|
23 |
+
|
24 |
+
_DATASETNAME = "fsl_105"
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
FSL-105 is a video dataset for 105 different Filipino Sign Language (FSL) signs.
|
28 |
+
Each sign is categorized into one of 10 categories and is each represented by approximately 20 four-second video samples.
|
29 |
+
Signs were performed by adult deaf FSL signers on a blank blue background and reviewed by an FSL expert.
|
30 |
+
"""
|
31 |
+
|
32 |
+
_HOMEPAGE = "https://data.mendeley.com/datasets/48y2y99mb9/2"
|
33 |
+
|
34 |
+
_LICENSE = Licenses.CC_BY_4_0.value
|
35 |
+
|
36 |
+
_LOCAL = False
|
37 |
+
|
38 |
+
_URLS = {
|
39 |
+
"clips": "https://prod-dcd-datasets-public-files-eu-west-1.s3.eu-west-1.amazonaws.com/de95a3c3-02f4-4a3f-9a9e-ce2371160275",
|
40 |
+
"train": "https://prod-dcd-datasets-public-files-eu-west-1.s3.eu-west-1.amazonaws.com/09c71779-3a2a-4c98-8d9b-0ef74f54d92a",
|
41 |
+
"test": "https://prod-dcd-datasets-public-files-eu-west-1.s3.eu-west-1.amazonaws.com/39af8117-6b44-47b9-a551-0bdc40837295",
|
42 |
+
}
|
43 |
+
|
44 |
+
_LANGUAGES = ["psp"]
|
45 |
+
|
46 |
+
_SUPPORTED_TASKS = [Tasks.VIDEO_TO_TEXT_RETRIEVAL, Tasks.VIDEO_CAPTIONING]
|
47 |
+
|
48 |
+
_SOURCE_VERSION = "1.0.0"
|
49 |
+
|
50 |
+
_SEACROWD_VERSION = "2024.06.20"
|
51 |
+
|
52 |
+
|
53 |
+
class FSL105Dataset(datasets.GeneratorBasedBuilder):
|
54 |
+
"""
|
55 |
+
FSL-105 is a video dataset for 105 different Filipino Sign Language (FSL) signs.
|
56 |
+
Each sign is categorized into one of 10 categories and is each represented by approximately 20 four-second video samples.
|
57 |
+
Signs were performed by adult deaf FSL signers on a blank blue background and reviewed by an FSL expert.
|
58 |
+
"""
|
59 |
+
|
60 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
61 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
62 |
+
|
63 |
+
BUILDER_CONFIGS = [
|
64 |
+
SEACrowdConfig(
|
65 |
+
name=f"{_DATASETNAME}_source",
|
66 |
+
version=SOURCE_VERSION,
|
67 |
+
description=f"{_DATASETNAME} source schema",
|
68 |
+
schema="source",
|
69 |
+
subset_id=f"{_DATASETNAME}",
|
70 |
+
),
|
71 |
+
SEACrowdConfig(
|
72 |
+
name=f"{_DATASETNAME}_seacrowd_vidtext",
|
73 |
+
version=SEACROWD_VERSION,
|
74 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
75 |
+
schema="seacrowd_vidtext",
|
76 |
+
subset_id=f"{_DATASETNAME}",
|
77 |
+
),
|
78 |
+
]
|
79 |
+
|
80 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
81 |
+
|
82 |
+
category = [
|
83 |
+
"CALENDAR",
|
84 |
+
"COLOR",
|
85 |
+
"DAYS",
|
86 |
+
"DRINK",
|
87 |
+
"FAMILY",
|
88 |
+
"FOOD",
|
89 |
+
"GREETING",
|
90 |
+
"NUMBER",
|
91 |
+
"RELATIONSHIPS",
|
92 |
+
"SURVIVAL",
|
93 |
+
]
|
94 |
+
|
95 |
+
def _info(self) -> datasets.DatasetInfo:
|
96 |
+
if self.config.schema == "source":
|
97 |
+
features = datasets.Features(
|
98 |
+
{
|
99 |
+
"id": datasets.Value("string"),
|
100 |
+
"video_path": datasets.Value("string"),
|
101 |
+
"text": datasets.Value("string"),
|
102 |
+
"labels": datasets.ClassLabel(names=self.category),
|
103 |
+
"metadata": {
|
104 |
+
"resolution": {
|
105 |
+
"width": datasets.Value("int64"),
|
106 |
+
"height": datasets.Value("int64"),
|
107 |
+
},
|
108 |
+
"duration": datasets.Value("float32"),
|
109 |
+
"fps": datasets.Value("float32"),
|
110 |
+
},
|
111 |
+
}
|
112 |
+
)
|
113 |
+
|
114 |
+
elif self.config.schema == "seacrowd_vidtext":
|
115 |
+
features = schemas.video_features
|
116 |
+
|
117 |
+
return datasets.DatasetInfo(
|
118 |
+
description=_DESCRIPTION,
|
119 |
+
features=features,
|
120 |
+
homepage=_HOMEPAGE,
|
121 |
+
license=_LICENSE,
|
122 |
+
citation=_CITATION,
|
123 |
+
)
|
124 |
+
|
125 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
126 |
+
"""Returns SplitGenerators."""
|
127 |
+
|
128 |
+
clips = dl_manager.download_and_extract(_URLS["clips"])
|
129 |
+
train = dl_manager.download_and_extract(_URLS["train"])
|
130 |
+
test = dl_manager.download_and_extract(_URLS["test"])
|
131 |
+
|
132 |
+
train_df = pd.read_csv(train)
|
133 |
+
test_df = pd.read_csv(test)
|
134 |
+
|
135 |
+
return [
|
136 |
+
datasets.SplitGenerator(
|
137 |
+
name=datasets.Split.TRAIN,
|
138 |
+
gen_kwargs={
|
139 |
+
"filepath": {
|
140 |
+
"clips": clips,
|
141 |
+
"data": train_df,
|
142 |
+
},
|
143 |
+
"split": "train",
|
144 |
+
},
|
145 |
+
),
|
146 |
+
datasets.SplitGenerator(
|
147 |
+
name=datasets.Split.TEST,
|
148 |
+
gen_kwargs={
|
149 |
+
"filepath": {"clips": clips, "data": test_df},
|
150 |
+
"split": "test",
|
151 |
+
},
|
152 |
+
),
|
153 |
+
]
|
154 |
+
|
155 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
156 |
+
"""Yields examples as (key, example) tuples."""
|
157 |
+
|
158 |
+
for key, example in filepath["data"].iterrows():
|
159 |
+
video = cv2.VideoCapture(os.path.join(filepath["clips"], PureWindowsPath(example["vid_path"]).as_posix()))
|
160 |
+
fps = video.get(cv2.CAP_PROP_FPS)
|
161 |
+
frame_count = video.get(cv2.CAP_PROP_FRAME_COUNT)
|
162 |
+
duration = frame_count / fps
|
163 |
+
vid_width = video.get(cv2.CAP_PROP_FRAME_WIDTH)
|
164 |
+
vid_height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
165 |
+
|
166 |
+
if self.config.schema == "source":
|
167 |
+
yield key, {
|
168 |
+
"id": str(key),
|
169 |
+
"video_path": os.path.join(filepath["clips"], example["vid_path"]),
|
170 |
+
"text": example["label"],
|
171 |
+
"labels": example["category"],
|
172 |
+
"metadata": {
|
173 |
+
"resolution": {
|
174 |
+
"width": vid_width,
|
175 |
+
"height": vid_height,
|
176 |
+
},
|
177 |
+
"duration": duration,
|
178 |
+
"fps": fps,
|
179 |
+
},
|
180 |
+
}
|
181 |
+
elif self.config.schema == "seacrowd_vidtext":
|
182 |
+
yield key, {
|
183 |
+
"id": str(key),
|
184 |
+
"video_path": os.path.join(filepath["clips"], example["vid_path"]),
|
185 |
+
"text": example["label"],
|
186 |
+
"metadata": {
|
187 |
+
"resolution": {
|
188 |
+
"width": vid_width,
|
189 |
+
"height": vid_height,
|
190 |
+
},
|
191 |
+
"duration": duration,
|
192 |
+
"fps": fps,
|
193 |
+
},
|
194 |
+
}
|