Skip to content

Commit 224e7c9

Browse files
committed
feat(dgs_types): add process_pose feature
1 parent b2fe4f8 commit 224e7c9

File tree

5 files changed

+30
-135
lines changed

5 files changed

+30
-135
lines changed

examples/load_all.py

+13-126
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,18 @@
1-
# import itertools
2-
#
3-
# import tensorflow_datasets as tfds
4-
# from dotenv import load_dotenv
5-
#
6-
# # noinspection PyUnresolvedReferences
7-
# # from sign_language_datasets.datasets.dgs_corpus import DgsCorpusConfig
8-
# from sign_language_datasets.datasets.dgs_corpus import DgsCorpusConfig
9-
#
10-
# import sign_language_datasets.datasets
11-
#
12-
# # noinspection PyUnresolvedReferences
13-
# # import sign_language_datasets.datasets.dgs_corpus
14-
# from sign_language_datasets.datasets.config import SignDatasetConfig
15-
# # from sign_language_datasets.datasets.dgs_corpus.dgs_corpus import DgsCorpusConfig
16-
#
17-
# load_dotenv()
18-
#
19-
# # config = SignDatasetConfig(name="only-annotations", version="3.0.0", include_video=False)
20-
# # rwth_phoenix2014_t = tfds.load(name="rwth_phoenix2014_t", builder_kwargs=dict(config=config))
21-
#
22-
# # config = SignDatasetConfig(name="256x256:10", include_video=True, fps=10, resolution=(256, 256))
23-
#
24-
# # aslg_pc12 = tfds.load('aslg_pc12')
25-
# #
26-
# # rwth_phoenix2014_t = tfds.load('rwth_phoenix2014_t', builder_kwargs=dict(config=config))
27-
#
28-
# # wlasl = tfds.load('wlasl', builder_kwargs=dict(config=config))
29-
# #
30-
# # autsl = tfds.load('autsl', builder_kwargs=dict(
31-
# # config=SignDatasetConfig(name="test", include_video=False, include_pose="holistic"),
32-
# # ))
33-
#
34-
# # dgs_config = DgsCorpusConfig(name="sentence-test-video", data_type="sentence",
35-
# # include_video=False, process_video=False, include_pose=None)
36-
# # dgs_corpus = tfds.load('dgs_corpus', builder_kwargs=dict(config=dgs_config))
37-
# #
38-
# # for datum in itertools.islice(dgs_corpus["train"], 0, 10):
39-
# # print(datum)
40-
#
41-
#
42-
# config = SignDatasetConfig(name="signbank-annotations", version="1.0.0", include_video=False)
43-
# signbank = tfds.load('sign_bank', builder_kwargs=dict(config=config))
44-
#
45-
# # config = SignDatasetConfig(name="signsuisse3", version="1.0.0", include_video=False, include_pose="holistic")
46-
# # signsuisse = tfds.load('sign_suisse', builder_kwargs=dict(config=config))
47-
#
48-
# # print([d["p.ose"]["data"].shape for d in iter(autsl["train"])])
49-
# # print([d["video"].shape for d in iter(autsl["train"])])
50-
#
51-
# # config = SignDatasetConfig(name="include4", version="1.0.0", extra={"PHPSESSID": "hj9co07ct7f5noq529no9u09l4"})
52-
# # signtyp = tfds.load(name='sign_typ', builder_kwargs=dict(config=config))
53-
# #
54-
# # for datum in itertools.islice(signtyp["train"], 0, 10):
55-
# # print(datum['sign_writing'].numpy().decode('utf-8'), datum['video'].numpy().decode('utf-8'))
56-
# #
57-
# # config = SignDatasetConfig(name="poses_1", version="1.0.0", include_video=False, include_pose="holistic")
58-
# # dicta_sign = tfds.load(name='dicta_sign', builder_kwargs={"config": config})
59-
#
60-
# # config = SignDatasetConfig(name="only-annotations5", version="1.0.0", include_video=False, process_video=False, include_pose="holistic")
61-
# # dataset = tfds.load(name='sign_bank', builder_kwargs=dict(config=SignDatasetConfig(name="annotations")))
62-
# #
63-
# # decode_str = lambda s: s.numpy().decode('utf-8')
64-
# # for datum in itertools.islice(dataset["train"], 0, 10):
65-
# # hamnosys = decode_str(datum['hamnosys'])
66-
# # glosses = [decode_str(g) for g in datum["glosses"]]
67-
# # print(hamnosys, glosses)
68-
#
69-
#
70-
# #
71-
# # import tensorflow_datasets as tfds
72-
# # # noinspection PyUnresolvedReferences
73-
# # import sign_language_datasets.datasets
74-
# # from sign_language_datasets.datasets.config import SignDatasetConfig
75-
# #
76-
# # # Populate your access tokens
77-
# # TOKENS = {
78-
# # "zenodo_focusnews_token": "TODO",
79-
# # "zenodo_srf_videos_token": "TODO",
80-
# # "zenodo_srf_poses_token": "TODO"
81-
# # }
82-
# #
83-
# # # Load only the annotations, and include path to video files
84-
# # config = SignDatasetConfig(name="annotations", version="1.0.0", process_video=False)
85-
# # wmtslt = tfds.load(name='wmtslt', builder_kwargs={"config": config, **TOKENS})
86-
# #
87-
# # # Load the annotations and openpose poses
88-
# # config = SignDatasetConfig(name="openpose", version="1.0.0", process_video=False, include_pose='openpose')
89-
# # wmtslt = tfds.load(name='wmtslt', builder_kwargs={"config": config, **TOKENS})
90-
# #
91-
# # # Load the annotations and mediapipe holistic poses
92-
# # config = SignDatasetConfig(name="holistic", version="1.0.0", process_video=False, include_pose='holistic')
93-
# # wmtslt = tfds.load(name='wmtslt', builder_kwargs={"config": config, **TOKENS})
94-
# #
95-
# # # Load the full video frames as a tensor
96-
# # config = SignDatasetConfig(name="videos", version="1.0.0", process_video=True)
97-
# # wmtslt = tfds.load(name='wmtslt', builder_kwargs={"config": config, **TOKENS})
98-
# #
99-
# decode_str = lambda s: s.numpy().decode('utf-8')
100-
# for datum in itertools.islice(signsuisse["train"], 0, 10):
101-
# print(datum)
102-
# print(datum["pose"])
103-
# print('\n')
104-
#
105-
#
106-
#
1+
import itertools
1072

108-
import tensorflow_datasets as tfds
109-
import sign_language_datasets.datasets
1103
from sign_language_datasets.datasets.config import SignDatasetConfig
4+
import tensorflow_datasets as tfds
1115

112-
import itertools
113-
#
114-
# config = SignDatasetConfig(name="holistic-poses", version="3.0.0", include_video=False, include_pose="holistic")
115-
# rwth_phoenix2014_t = tfds.load(name='rwth_phoenix2014_t', builder_kwargs=dict(config=config))
116-
#
117-
# for datum in itertools.islice(rwth_phoenix2014_t["train"], 0, 10):
118-
# print(datum['gloss'].numpy().decode('utf-8'))
119-
# print(datum['text'].numpy().decode('utf-8'))
120-
# print(datum['pose']['data'].shape)
121-
# print()
122-
6+
config = SignDatasetConfig(
7+
name="pose_holistic_paths2",
8+
version="3.0.0",
9+
include_video=False,
10+
include_pose="holistic",
11+
process_pose=False
12+
)
12313

124-
config = SignDatasetConfig(name="holistic-poses", version="1.0.0", include_video=False, include_pose="holistic")
125-
mediapi_skel = tfds.load(name='mediapi_skel', builder_kwargs=dict(config=config))
14+
# Load the dgs_types dataset with the specified configuration
15+
dgs_types = tfds.load('dgs_types', builder_kwargs=dict(config=config))
12616

127-
for datum in itertools.islice(mediapi_skel["test"], 0, 10):
128-
print(datum['id'].numpy().decode('utf-8'))
129-
print(datum['subtitles'])
130-
print(datum['pose']['data'].shape)
131-
print()
17+
for datum in dgs_types["train"].take(10):
18+
print(datum)

sign_language_datasets/datasets/autsl/autsl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tensorflow as tf
1010
import tensorflow_datasets as tfds
1111
from tensorflow.io.gfile import GFile
12-
from tensorflow_datasets.core.download.resource import get_dl_dirname
12+
from tensorflow_datasets.core.download.resource import get_dl_fname
1313
from tqdm import tqdm
1414

1515
from ..warning import dataset_warning
@@ -123,7 +123,7 @@ def _download_and_extract_multipart(self, dl_manager: tfds.download.DownloadMana
123123
print(_OPENPOSE_DISCLAIMER)
124124

125125
# Make sure not already downloaded
126-
dirname = get_dl_dirname(url)
126+
dirname = get_dl_fname(url)
127127
output_path = os.path.join(dl_manager._download_dir, dirname)
128128
output_path_extracted = os.path.join(dl_manager._extract_dir, dirname)
129129

sign_language_datasets/datasets/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(
1616
include_video: bool = True,
1717
process_video: bool = None,
1818
include_pose: Optional[str] = None,
19+
process_pose: bool = True,
1920
fps: Optional[float] = None,
2021
resolution: Optional[Tuple[int, int]] = None,
2122
sample_size: Optional[int] = None,
@@ -36,6 +37,7 @@ def __init__(
3637
self.include_video = include_video
3738
self.process_video = process_video if process_video is not None else include_video
3839
self.include_pose = include_pose.lower() if include_pose is not None else None
40+
self.process_pose = process_pose
3941

4042
self.fps = fps
4143
self.resolution = resolution

sign_language_datasets/datasets/dgs_types/dgs_types.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ def _info(self) -> tfds.core.DatasetInfo:
6161

6262
# Add poses if requested
6363
if self._builder_config.include_pose == "holistic":
64-
pose_header_path = _POSE_HEADERS[self._builder_config.include_pose]
65-
stride = 1 if self._builder_config.fps is None else 25 / self._builder_config.fps
66-
pose_shape = (None, 1, 576, 3)
67-
video_feature["pose"] = PoseFeature(shape=pose_shape, stride=stride, header_path=pose_header_path)
64+
if self._builder_config.process_pose:
65+
pose_header_path = _POSE_HEADERS[self._builder_config.include_pose]
66+
stride = 1 if self._builder_config.fps is None else 25 / self._builder_config.fps
67+
pose_shape = (None, 1, 576, 3)
68+
pose_feature = PoseFeature(shape=pose_shape, stride=stride, header_path=pose_header_path)
69+
else:
70+
pose_feature = tfds.features.Text()
71+
72+
video_feature["pose"] = pose_feature
6873

6974
features = {
7075
"id": tfds.features.Text(),
@@ -100,6 +105,7 @@ def get_galex_data(self, dl_manager: tfds.download.DownloadManager):
100105
content = f.read()
101106
gloss = re.findall(r"span class=\"Gloss\">(.*?)<", content)[0]
102107
video = re.findall(r"source src=\"\.\.\/(.*?)\"", content)[0]
108+
video = video.replace('filmekl/', 'filmegr/') # higher resolution videos
103109
datum = {
104110
"id": "galex_" + gloss,
105111
"glosses": [gloss],
@@ -204,9 +210,9 @@ def _generate_examples(self, data, poses):
204210
if self._builder_config.include_pose:
205211
pose_view = f"{datum['id']}_{view['name']}"
206212
if pose_view in poses:
207-
view["pose"] = poses[pose_view]
213+
view["pose"] = str(poses[pose_view])
208214
else:
209215
print(f"No pose for {pose_view}.")
210-
view["pose"] = None
216+
view["pose"] = ""
211217

212218
yield datum["id"], datum

sign_language_datasets/utils/features/pose_feature.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def encode_body(self, file_path: str, body: PoseBody):
152152
def encode_example(self, pose_path_or_fobj):
153153
"""Convert the given image into a dict convertible to tf example."""
154154

155-
if pose_path_or_fobj is None:
155+
if pose_path_or_fobj is None or pose_path_or_fobj == "":
156156
# Create 0 size tensors
157157
data_shape = list(self._shape)
158158
data_shape[0] = 0

0 commit comments

Comments
 (0)