mikewang commited on
Commit
d3e197b
·
1 Parent(s): 3a94689

first commit

Browse files
Files changed (2) hide show
  1. README.md +36 -1
  2. imsitu.py +203 -0
README.md CHANGED
@@ -1,3 +1,38 @@
1
  ---
2
- license: unknown
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pretty_name: 'imSitu dataset'
3
+ language:
4
+ - en
5
  ---
6
+ # Dataset Card for imSitu
7
+
8
+ ## Dataset Description
9
+
10
+ **Homepage:** http://imsitu.org/
11
+
12
+ **Repository:** https://github.com/my89/imSitu;
13
+ - The metadata used for imSitu: https://github.com/my89/imSitu#metadata
14
+ - The images can be downloaded following: https://github.com/my89/imSitu#images
15
+ - This HF dataset loads the `train.json`, `val.json` and `test.json` from the repository
16
+
17
+ **IMPORTANT NOTE**: The `frames` field in the loaded HF dataset contains a list of json strings (since the data structure for each verb frame is different). To convert the json strings back to dicts, you can refer to the following example:
18
+ ```
19
+ from datasets import load_dataset
20
+ import json
21
+ dataset = load_dataset("mikewang/imsitu")
22
+ print(dataset['train'][0])
23
+ frames = [json.loads(obj) for obj in dataset['train'][0]['frames']]
24
+ print(frames)
25
+ ```
26
+
27
+ **Paper Citation:**
28
+ ```
29
+ @inproceedings{yatskar2016,
30
+ title={Situation Recognition: Visual Semantic Role Labeling for Image Understanding},
31
+ author={Yatskar, Mark and Zettlemoyer, Luke and Farhadi, Ali},
32
+ booktitle={Conference on Computer Vision and Pattern Recognition},
33
+ year={2016}
34
+ }
35
+ ```
36
+
37
+ ## Dataset Summary
38
+ imSitu is a dataset supporting situation recognition, the problem of producing a concise summary of the situation an image depicts including: (1) the main activity, (2) the participating actors, objects, substances, and locations and most importantly (3) the roles these participants play in the activity. The role set used by imSitu is derived from the linguistic resource FrameNet and the entities are derived from ImageNet. The data in imSitu can be used to create robust algorithms for situation recongntion.
imsitu.py ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """imSitu dataset"""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+ _CITATION = """\
25
+ @inproceedings{yatskar2016,
26
+ title={Situation Recognition: Visual Semantic Role Labeling for Image Understanding},
27
+ author={Yatskar, Mark and Zettlemoyer, Luke and Farhadi, Ali},
28
+ booktitle={Conference on Computer Vision and Pattern Recognition},
29
+ year={2016}
30
+ }
31
+ """
32
+
33
+ # TODO: Add description of the dataset here
34
+ # You can copy an official description
35
+ _DESCRIPTION = """\
36
+ imSitu is a dataset supporting situation recognition, the problem of producing a concise summary of the situation an image depicts including: (1) the main activity, (2) the participating actors, objects, substances, and locations and most importantly (3) the roles these participants play in the activity. The role set used by imSitu is derived from the linguistic resource FrameNet and the entities are derived from ImageNet. The data in imSitu can be used to create robust algorithms for situation recongntion.
37
+
38
+ Repository: https://github.com/my89/imSitu;
39
+ - The metadata used for imSitu: https://github.com/my89/imSitu#metadata
40
+ - The images can be downloaded following: https://github.com/my89/imSitu#images
41
+ - This HF dataset loads the `train.json`, `val.json` and `test.json` from the repository
42
+ """
43
+
44
+ # TODO: Add a link to an official homepage for the dataset here
45
+ _HOMEPAGE = "http://imsitu.org/"
46
+
47
+ # TODO: Add the licence for the dataset here if you can find it
48
+ _LICENSE = ""
49
+
50
+ # TODO: Add link to the official dataset URLs here
51
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
52
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
53
+ # _URLS = {
54
+ # # "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
55
+ # # "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
56
+ # }
57
+
58
+ _URL = "https://raw.githubusercontent.com/my89/imSitu/master/"
59
+ _URLS = {
60
+ "train": _URL + "train.json",
61
+ "val": _URL + "dev.json",
62
+ "test": _URL + "test.json"
63
+ }
64
+
65
+
66
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
67
+ class imSitu(datasets.GeneratorBasedBuilder):
68
+ """TODO: Short description of my dataset."""
69
+
70
+ VERSION = datasets.Version("1.0.0")
71
+
72
+ # This is an example of a dataset with multiple configurations.
73
+ # If you don't want/need to define several sub-sets in your dataset,
74
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
75
+
76
+ # If you need to make complex sub-parts in the datasets with configurable options
77
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
78
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
79
+
80
+ # You will be able to load one or the other configurations in the following list with
81
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
82
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
83
+ # BUILDER_CONFIGS = [
84
+ # datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
85
+ # datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
86
+ # ]
87
+
88
+ # DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
89
+
90
+ def _info(self):
91
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
92
+ # if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
93
+ # features = datasets.Features(
94
+ # {
95
+ # "sentence": datasets.Value("string"),
96
+ # "option1": datasets.Value("string"),
97
+ # "answer": datasets.Value("string")
98
+ # # These are the features of your dataset like images, labels ...
99
+ # }
100
+ # )
101
+ # else: # This is an example to show how to have different features for "first_domain" and "second_domain"
102
+ # features = datasets.Features(
103
+ # {
104
+ # "sentence": datasets.Value("string"),
105
+ # "option2": datasets.Value("string"),
106
+ # "second_domain_answer": datasets.Value("string")
107
+ # # These are the features of your dataset like images, labels ...
108
+ # }
109
+ # )
110
+
111
+ features = datasets.Features(
112
+ {
113
+ "image_id": datasets.Value("string"), # int (Image ids correspond to respective Visual Genome image ids)
114
+ "frames":datasets.features.Sequence(datasets.Value("string")), # list of jsonl strings indicating frames
115
+ "verb": datasets.Value("string"),
116
+ }
117
+ )
118
+
119
+ return datasets.DatasetInfo(
120
+ # This is the description that will appear on the datasets page.
121
+ description=_DESCRIPTION,
122
+ # This defines the different columns of the dataset and their types
123
+ features=features, # Here we define them above because they are different between the two configurations
124
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
125
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
126
+ # supervised_keys=("sentence", "label"),
127
+ # Homepage of the dataset for documentation
128
+ homepage=_HOMEPAGE,
129
+ # License for the dataset if available
130
+ license=_LICENSE,
131
+ # Citation for the dataset
132
+ citation=_CITATION,
133
+ )
134
+
135
+ def _split_generators(self, dl_manager):
136
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
137
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
138
+
139
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
140
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
141
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
142
+
143
+ # urls = _URLS[self.config.name]
144
+ # data_dir = dl_manager.download_and_extract(urls)
145
+
146
+ downloaded_files = dl_manager.download_and_extract(_URLS)
147
+ print("downloaded_files: ", downloaded_files)
148
+ return [
149
+ datasets.SplitGenerator(
150
+ name=datasets.Split.TRAIN,
151
+ # These kwargs will be passed to _generate_examples
152
+ gen_kwargs={
153
+ "filepath": downloaded_files["train"],
154
+ "split": "train",
155
+ },
156
+ ),
157
+ datasets.SplitGenerator(
158
+ name=datasets.Split.VALIDATION,
159
+ # These kwargs will be passed to _generate_examples
160
+ gen_kwargs={
161
+ "filepath": downloaded_files["val"],
162
+ "split": "val",
163
+ },
164
+ ),
165
+ datasets.SplitGenerator(
166
+ name=datasets.Split.TEST,
167
+ # These kwargs will be passed to _generate_examples
168
+ gen_kwargs={
169
+ "filepath": downloaded_files["test"],
170
+ "split": "test"
171
+ },
172
+ ),
173
+ ]
174
+
175
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
176
+ def _generate_examples(self, filepath, split):
177
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
178
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
179
+ # with open(filepath, encoding="utf-8") as f:
180
+ # for key, row in enumerate(f):
181
+ # data = json.loads(row)
182
+ # if self.config.name == "first_domain":
183
+ # # Yields examples as (key, example) tuples
184
+ # yield key, {
185
+ # "sentence": data["sentence"],
186
+ # "option1": data["option1"],
187
+ # "answer": "" if split == "test" else data["answer"],
188
+ # }
189
+ # else:
190
+ # yield key, {
191
+ # "sentence": data["sentence"],
192
+ # "option2": data["option2"],
193
+ # "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
194
+ # }
195
+
196
+ data = json.load(open(filepath, encoding="utf-8"))
197
+
198
+ for key, row in data.items():
199
+ yield key, {
200
+ "image_id": key,
201
+ "frames": [json.dumps(obj) for obj in row["frames"]],
202
+ "verb": row["verb"]
203
+ }