mwhanna commited on
Commit
93086fa
·
1 Parent(s): 6779234

Upload ACT-Thor.py

Browse files
Files changed (1) hide show
  1. ACT-Thor.py +124 -0
ACT-Thor.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adapted from the dataset builders for the Winoground Dataset (https://huggingface.co/datasets/facebook/winoground)
2
+ import os
3
+ import ast
4
+
5
+ import datasets
6
+ import json
7
+ import pandas as pd
8
+ # from huggingface_hub import hf_hub_url
9
+
10
+
11
+ _CITATION = """\
12
+ @inproceedings{hanna-etal-2022-act,
13
+ title = "ACT-Thor: A Controlled Benchmark for Embodied Action Understanding in Simulated Environments",
14
+ author = "Hanna, Michael and
15
+ Pedeni, Federico and
16
+ Suglia, Alessandro and
17
+ Testoni, Alberto and
18
+ Bernardi, Raffaella",
19
+ booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
20
+ month = oct,
21
+ year = "2022",
22
+ address = "Gyeongju, South Korea",
23
+ publisher = "International Committee on Computational Linguistics",
24
+ }
25
+ """
26
+
27
+ _URL = "https://huggingface.co/datasets/mwhanna/ACT-Thor"
28
+
29
+ _DESCRIPTION = """\
30
+ ACT-Thor is a dataset intended for evaluating models' understanding of actions.
31
+ """
32
+
33
+
34
+ class ACTThorConfig(datasets.BuilderConfig):
35
+ """BuilderConfig for ACT-Thor."""
36
+
37
+ def __init__(self, split_type, **kwargs):
38
+ """BuilderConfig for ACT-Thor.
39
+ Args:
40
+ **kwargs: keyword arguments forwarded to super.
41
+ """
42
+ super(ACTThorConfig, self).__init__(**kwargs)
43
+ self.split_type = split_type
44
+
45
+
46
+
47
+ class ACTThor(datasets.GeneratorBasedBuilder):
48
+ BUILDER_CONFIG_CLASS = ACTThorConfig
49
+
50
+ BUILDER_CONFIGS = [
51
+ ACTThorConfig('sample',
52
+ name="sample",
53
+ ),
54
+ ACTThorConfig('object',
55
+ name="object",
56
+ ),
57
+ ACTThorConfig('scene',
58
+ name="scene",
59
+ ),
60
+ ]
61
+
62
+ DEFAULT_CONFIG_NAME = "sample"
63
+
64
+ IMAGE_EXTENSION = ".png"
65
+
66
+ def _info(self):
67
+ return datasets.DatasetInfo(
68
+ description=_DESCRIPTION,
69
+ features=datasets.Features(
70
+ {
71
+ "id": datasets.Value("int32"),
72
+ "before_image": datasets.Image(),
73
+ "after_image_0": datasets.Image(),
74
+ "after_image_1": datasets.Image(),
75
+ "after_image_2": datasets.Image(),
76
+ "after_image_3": datasets.Image(),
77
+ "action": datasets.Value("string"),
78
+ "action_id": datasets.Value("int32"),
79
+ "label": datasets.Value("int32"),
80
+ "object": datasets.Value("string"),
81
+ "scene": datasets.Value("string"),
82
+ }
83
+ ),
84
+ homepage=_URL,
85
+ citation=_CITATION,
86
+ task_templates=[],
87
+ )
88
+
89
+ def _split_generators(self, dl_manager):
90
+ """Returns SplitGenerators."""
91
+
92
+ # hf_auth_token = dl_manager.download_config.use_auth_token
93
+ # if hf_auth_token is None:
94
+ # raise ConnectionError(
95
+ # "Please set use_auth_token=True or use_auth_token='<TOKEN>' to download this dataset"
96
+ # )
97
+
98
+ downloaded_files = dl_manager.download_and_extract({
99
+ "examples_csv": 'https://www.dropbox.com/s/4xdlimis1lv17x4/dataset_hf.csv?dl=1', # hf_hub_url("datasets/facebook/winoground", filename="data/examples.jsonl"),
100
+ "images_dir": 'https://www.dropbox.com/s/odkkrtvogi8go76/images.zip?dl=1', # hf_hub_url("datasets/facebook/winoground", filename="data/images.zip")
101
+ })
102
+
103
+ split_type = self.config.split_type
104
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'split_type': split_type, 'split':'train', **downloaded_files}),
105
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={'split_type': split_type, 'split':'valid', **downloaded_files}),
106
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={'split_type': split_type, 'split':'test', **downloaded_files})]
107
+
108
+ def _generate_examples(self, examples_csv, images_dir, split_type, split):
109
+ """Yields examples."""
110
+ #print('The examples csv is stored in ')
111
+ #print(examples_csv)
112
+ df = pd.read_csv(examples_csv)
113
+ df = df[df[f'{split_type}_split'] == split]
114
+ df = df.drop(['sample_split', 'object_split', 'scene_split'], axis='columns')
115
+ for example in df.to_dict('records'):
116
+ order = ast.literal_eval(example['order'])
117
+ example["before_image"] = os.path.join(images_dir, "images", "before_images", example["before_image"] + self.IMAGE_EXTENSION)
118
+ example["after_image_0"] = os.path.join(images_dir, "images", "after_images", example[f"after_image_{order[0]}"] + self.IMAGE_EXTENSION)
119
+ example["after_image_1"] = os.path.join(images_dir, "images", "after_images", example[f"after_image_{order[1]}"] + self.IMAGE_EXTENSION)
120
+ example["after_image_2"] = os.path.join(images_dir, "images", "after_images", example[f"after_image_{order[2]}"] + self.IMAGE_EXTENSION)
121
+ example["after_image_3"] = os.path.join(images_dir, "images", "after_images", example[f"after_image_{order[3]}"] + self.IMAGE_EXTENSION)
122
+ id_ = example["id"]
123
+ del example['order']
124
+ yield id_, example