Datasets:

Tasks:
Other
Languages:
English
ArXiv:
License:
File size: 6,922 Bytes
a4a96fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc05460
fc55cd7
 
a4a96fc
bc05460
a4a96fc
 
 
 
 
 
 
 
 
 
 
 
 
 
bc05460
a4a96fc
fc55cd7
 
bc05460
 
a4a96fc
 
 
fc55cd7
 
 
a4a96fc
 
fc55cd7
 
 
 
a4a96fc
 
 
 
 
fc55cd7
 
 
bc05460
a4a96fc
 
 
 
 
fc55cd7
 
 
bc05460
a4a96fc
 
 
bc05460
a4a96fc
bc05460
 
fc55cd7
 
 
a4a96fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc55cd7
 
 
a4a96fc
 
 
 
 
fc55cd7
a4a96fc
fc55cd7
a4a96fc
 
fc55cd7
a4a96fc
 
 
 
bc05460
fc55cd7
 
a4a96fc
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""The Something-Something dataset (version 2) is a collection of 220,847 labeled video clips of humans performing pre-defined, basic actions with everyday objects."""


import csv
import json
import os

import datasets

from .classes import SOMETHING_SOMETHING_V2_CLASSES

_CITATION = """
@inproceedings{goyal2017something,
  title={The" something something" video database for learning and evaluating visual common sense},
  author={Goyal, Raghav and Ebrahimi Kahou, Samira and Michalski, Vincent and Materzynska, Joanna and Westphal, Susanne and Kim, Heuna and Haenel, Valentin and Fruend, Ingo and Yianilos, Peter and Mueller-Freitag, Moritz and others},
  booktitle={Proceedings of the IEEE international conference on computer vision},
  pages={5842--5850},
  year={2017}
}
"""

_DESCRIPTION = """\
The Something-Something dataset (version 2) is a collection of 220,847 labeled video clips of humans performing pre-defined, basic actions with everyday objects. It is designed to train machine learning models in fine-grained understanding of human hand gestures like putting something into something, turning something upside down and covering something with something.
"""


class SomethingSomethingV2(datasets.GeneratorBasedBuilder):
    """Charades is dataset composed of 9848 videos of daily indoors activities collected through Amazon Mechanical Turk"""

    BUILDER_CONFIGS = [datasets.BuilderConfig(name="default")]
    DEFAULT_CONFIG_NAME = "default"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "video_id": datasets.Value("string"),
                    "video": datasets.Value("string"),
                    "text": datasets.Value("string"),
                    "label": datasets.features.ClassLabel(
                        num_classes=len(SOMETHING_SOMETHING_V2_CLASSES),
                        names=SOMETHING_SOMETHING_V2_CLASSES,
                    ),
                    "placeholders": datasets.Sequence(datasets.Value("string")),
                }
            ),
            supervised_keys=None,
            homepage="",
            citation=_CITATION,
        )

    @property
    def manual_download_instructions(self):
        return (
            "To use Something-Something-v2, please download the 19 data files and the labels file "
            "from 'https://developer.qualcomm.com/software/ai-datasets/something-something'. "
            "Unzip the 19 files and concatenate the extracts in order into a tar file named '20bn-something-something-v2.tar.gz. "
            "Use command like `cat 20bn-something-something-v2-?? >> 20bn-something-something-v2.tar.gz` "
            "Place the `labels.zip` file and the tar file into a folder '/path/to/data/' and load the dataset using "
            "`load_dataset('something-something-v2', data_dir='/path/to/data')`"
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.manual_dir
        labels_path = os.path.join(data_dir, "labels.zip")
        videos_path = os.path.join(data_dir, "20bn-something-something-v2.tar.gz")
        if not os.path.exists(labels_path):
            raise FileNotFoundError(
                f"labels.zip doesn't exist in {data_dir}. Please follow manual download instructions."
            )

        if not os.path.exists(videos_path):
            raise FileNotFoundError(
                f"20bn-something-sokmething-v2.tar.gz doesn't exist in {data_dir}. Please follow manual download instructions."
            )

        labels_path = dl_manager.extract(labels_path)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "annotation_file": os.path.join(
                        labels_path, "labels", "train.json"
                    ),
                    "video_files": dl_manager.iter_archive(videos_path),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "annotation_file": os.path.join(
                        labels_path, "labels", "validation.json"
                    ),
                    "video_files": dl_manager.iter_archive(videos_path),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "annotation_file": os.path.join(labels_path, "labels", "test.json"),
                    "video_files": dl_manager.iter_archive(videos_path),
                    "labels_file": os.path.join(
                        labels_path, "labels", "test-answers.csv"
                    ),
                },
            ),
        ]

    def _generate_examples(self, annotation_file, video_files, labels_file=None):
        data = {}
        labels = None
        if labels_file is not None:
            with open(labels_file, "r", encoding="utf-8") as fobj:
                labels = {}
                for label in fobj.readlines():
                    label = label.strip().split(";")
                    labels[label[0]] = label[1]

        with open(annotation_file, "r", encoding="utf-8") as fobj:
            annotations = json.load(fobj)
            for annotation in annotations:
                if "template" in annotation:
                    annotation["template"] = (
                        annotation["template"].replace("[", "").replace("]", "")
                    )
                if labels:
                    annotation["template"] = labels[annotation["id"]]
                data[annotation["id"]] = annotation

        idx = 0
        for path, file in video_files:
            video_id = os.path.splitext(os.path.split(path)[1])[0]

            if video_id not in data:
                continue

            info = data[video_id]
            yield idx, {
                "video_id": video_id,
                "video": file,
                "placeholders": info.get("placeholders", []),
                "label": info["label"] if "label" in info else -1,
                "text": info["template"],
            }

            idx += 1