aleksclark commited on
Commit
00d7c2d
1 Parent(s): 5207d2b
Files changed (2) hide show
  1. README.md +252 -0
  2. basic_shapes_10k.py +188 -0
README.md ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ - config_name: mixed
4
+ features:
5
+ - name: svg
6
+ dtype: string
7
+ - name: png
8
+ dtype: image
9
+ - name: layer_mask
10
+ dtype: image
11
+ - name: object_mask
12
+ dtype: image
13
+ splits:
14
+ - name: train
15
+ num_bytes: 44979830
16
+ num_examples: 32000
17
+ - name: validation
18
+ num_bytes: 5629432
19
+ num_examples: 4000
20
+ - name: test
21
+ num_bytes: 4389077
22
+ num_examples: 4000
23
+ download_size: 510689903
24
+ dataset_size: 54998339
25
+ - config_name: circles
26
+ features:
27
+ - name: svg
28
+ dtype: string
29
+ - name: png
30
+ dtype: image
31
+ - name: layer_mask
32
+ dtype: image
33
+ - name: object_mask
34
+ dtype: image
35
+ splits:
36
+ - name: train
37
+ num_bytes: 10970618
38
+ num_examples: 8000
39
+ - name: validation
40
+ num_bytes: 1373482
41
+ num_examples: 1000
42
+ - name: test
43
+ num_bytes: 1070432
44
+ num_examples: 1000
45
+ download_size: 220171148
46
+ dataset_size: 13414532
47
+ - config_name: squares
48
+ features:
49
+ - name: svg
50
+ dtype: string
51
+ - name: png
52
+ dtype: image
53
+ - name: layer_mask
54
+ dtype: image
55
+ - name: object_mask
56
+ dtype: image
57
+ splits:
58
+ - name: train
59
+ num_bytes: 11349095
60
+ num_examples: 8000
61
+ - name: validation
62
+ num_bytes: 1424342
63
+ num_examples: 1000
64
+ - name: test
65
+ num_bytes: 1115270
66
+ num_examples: 1000
67
+ download_size: 31759345
68
+ dataset_size: 13888707
69
+ - config_name: squares_and_circles
70
+ features:
71
+ - name: svg
72
+ dtype: string
73
+ - name: png
74
+ dtype: image
75
+ - name: layer_mask
76
+ dtype: image
77
+ - name: object_mask
78
+ dtype: image
79
+ splits:
80
+ - name: train
81
+ num_bytes: 11459654
82
+ num_examples: 8000
83
+ - name: validation
84
+ num_bytes: 1431454
85
+ num_examples: 1000
86
+ - name: test
87
+ num_bytes: 1096945
88
+ num_examples: 1000
89
+ download_size: 128738219
90
+ dataset_size: 13988053
91
+ - config_name: scer
92
+ features:
93
+ - name: svg
94
+ dtype: string
95
+ - name: png
96
+ dtype: image
97
+ - name: layer_mask
98
+ dtype: image
99
+ - name: object_mask
100
+ dtype: image
101
+ splits:
102
+ - name: train
103
+ num_bytes: 11200463
104
+ num_examples: 8000
105
+ - name: validation
106
+ num_bytes: 1400154
107
+ num_examples: 1000
108
+ - name: test
109
+ num_bytes: 1106430
110
+ num_examples: 1000
111
+ download_size: 130021191
112
+ dataset_size: 13707047
113
+ ---
114
+
115
+ # Dataset Card for BasicShapes10K
116
+
117
+ ## Table of Contents
118
+ - [Table of Contents](#table-of-contents)
119
+ - [Dataset Description](#dataset-description)
120
+ - [Dataset Summary](#dataset-summary)
121
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
122
+ - [Languages](#languages)
123
+ - [Dataset Structure](#dataset-structure)
124
+ - [Data Instances](#data-instances)
125
+ - [Data Fields](#data-fields)
126
+ - [Data Splits](#data-splits)
127
+ - [Dataset Creation](#dataset-creation)
128
+ - [Curation Rationale](#curation-rationale)
129
+ - [Source Data](#source-data)
130
+ - [Annotations](#annotations)
131
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
132
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
133
+ - [Social Impact of Dataset](#social-impact-of-dataset)
134
+ - [Discussion of Biases](#discussion-of-biases)
135
+ - [Other Known Limitations](#other-known-limitations)
136
+ - [Additional Information](#additional-information)
137
+ - [Dataset Curators](#dataset-curators)
138
+ - [Licensing Information](#licensing-information)
139
+ - [Citation Information](#citation-information)
140
+ - [Contributions](#contributions)
141
+
142
+ ## Dataset Description
143
+
144
+ - **Homepage:** https://eezy.com
145
+
146
+
147
+ ### Dataset Summary
148
+
149
+ This is a synthetic dataset containing randomly-generated SVGs with various shapes
150
+ ### Supported Tasks and Leaderboards
151
+
152
+ NA
153
+
154
+ ### Languages
155
+
156
+ NA
157
+
158
+ ## Dataset Structure
159
+
160
+ The dataset is composed of 4 base domains, plus a 'mixed' domain that is a superset of the other 4:
161
+ * `circles` - only circles
162
+ * `squares` - only squares
163
+ * `squares_and_circles` - circles and squares present in the same svg
164
+ * `scer` - squares, circles, ellipses, and rectangles present in the same svg
165
+ * `mixed` - an aggregation of all of the above
166
+
167
+ ### Data Instances
168
+
169
+ There's stuff there
170
+
171
+ ### Data Fields
172
+
173
+ Each example has 4 fields:
174
+
175
+ * `svg` - the raw svg as a string
176
+ * `png` - a raster rendering of the svg with a white background
177
+ * `object_mask` - a black/white mask that defines the outlines of the svg objects
178
+ * `layer_mask` - a greyscale mask that defines layers of svg objects - overlap regions are brighter. Created by making all the objects white and semi-transparent
179
+
180
+ ### Data Splits
181
+
182
+ Train & validation include the layer and object masks, test does not
183
+
184
+ ## Dataset Creation
185
+
186
+ Generated by randomly inserting objects into an SVG.
187
+
188
+ ### Curation Rationale
189
+
190
+ Objects should have at least 50% of their bounding box visible - i.e. no big circle completely obscuring a little circle
191
+
192
+ ### Source Data
193
+
194
+ `/dev/urandom`
195
+
196
+ #### Initial Data Collection and Normalization
197
+
198
+ NA
199
+
200
+ #### Who are the source language producers?
201
+
202
+ NA
203
+
204
+ ### Annotations
205
+
206
+ see [Data Fields](#data-fields)
207
+
208
+ #### Annotation process
209
+
210
+ see [Data Fields](#data-fields)
211
+
212
+ #### Who are the annotators?
213
+
214
+ Imagemagick/pysvg
215
+
216
+ ### Personal and Sensitive Information
217
+
218
+ Unlikely
219
+
220
+ ## Considerations for Using the Data
221
+
222
+ Please do not use for world domination.
223
+
224
+ ### Social Impact of Dataset
225
+
226
+ NA
227
+
228
+ ### Discussion of Biases
229
+
230
+ Dataset is highly biased against triangles and concave shapes
231
+
232
+ ### Other Known Limitations
233
+
234
+ Color selection is pretty limited.
235
+
236
+ ## Additional Information
237
+
238
+ ### Dataset Curators
239
+
240
+ [Aleks Clark](https://github.com/aleksclark)
241
+
242
+ ### Licensing Information
243
+
244
+ CC-BY
245
+
246
+ ### Citation Information
247
+
248
+ Link it I guess?
249
+
250
+ ### Contributions
251
+
252
+ Thanks to [@aleksclark](https://github.com/aleksclark) for adding this dataset.
basic_shapes_10k.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """A dataset consisting of svgs, their png representations, and various masks"""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ from math import floor
22
+
23
+ import datasets
24
+
25
+ # Find for instance the citation on arxiv or on the dataset repo/website
26
+ _CITATION = """\
27
+ @InProceedings{huggingface:dataset,
28
+ title = {A dataset for understanding vector graphics},
29
+ author={eezy, Inc.
30
+ },
31
+ year={2023}
32
+ }
33
+ """
34
+
35
+ # You can copy an official description
36
+ _DESCRIPTION = """\
37
+ This new dataset is designed to provide a corpus for training machine vision tasks on the understanding of basic vector graphics
38
+ """
39
+
40
+ _HOMEPAGE = "https://eezy.com"
41
+
42
+ # TODO: Add the licence for the dataset here if you can find it
43
+ _LICENSE = "CC-BY"
44
+
45
+ # TODO: Add link to the official dataset URLs here
46
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
47
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
48
+ _URLS = {
49
+ "circles": "https://eezy-data-bucket.s3.amazonaws.com/public-datasets/basic_shapes_10k_v1/circles.tgz",
50
+ "squares": "https://eezy-data-bucket.s3.amazonaws.com/public-datasets/basic_shapes_10k_v1/squares.tgz",
51
+ "squares_and_circles": "https://eezy-data-bucket.s3.amazonaws.com/public-datasets/basic_shapes_10k_v1/squares_and_circles.tgz",
52
+ "scer": "https://eezy-data-bucket.s3.amazonaws.com/public-datasets/basic_shapes_10k_v1/scer.tgz"
53
+ }
54
+
55
+
56
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
57
+ class BasicShapes10K(datasets.GeneratorBasedBuilder):
58
+ """A dataset consisting of simple vector shapes and various kinds of masks"""
59
+
60
+ VERSION = datasets.Version("1.0.0")
61
+
62
+ SPLIT_COUNTS = {
63
+ 'train': (0, 8000),
64
+ 'dev': (8000, 9000),
65
+ 'test': (9000, 10000)
66
+ }
67
+
68
+ BUILDER_CONFIGS = [
69
+ datasets.BuilderConfig(name="mixed", version=VERSION, description="These images are a mixture of all the other datasets"),
70
+ datasets.BuilderConfig(name="circles", version=VERSION, description="These images only contain circles"),
71
+ datasets.BuilderConfig(name="squares", version=VERSION, description="These images only contain squares"),
72
+ datasets.BuilderConfig(name="squares_and_circles", version=VERSION, description="These images contain circles and squares"),
73
+ datasets.BuilderConfig(name="scer", version=VERSION, description="These images contain circles, squares, rectangles, and ellipses"),
74
+ ]
75
+
76
+ DEFAULT_CONFIG_NAME = "mixed" # It's not mandatory to have a default configuration. Just use one if it make sense.
77
+
78
+ def _info(self):
79
+ features = datasets.Features(
80
+ {
81
+ "svg": datasets.Value("string"),
82
+ "png": datasets.Image(),
83
+ "layer_mask": datasets.Image(),
84
+ "object_mask": datasets.Image(),
85
+ }
86
+ )
87
+ return datasets.DatasetInfo(
88
+ # This is the description that will appear on the datasets page.
89
+ description=_DESCRIPTION,
90
+ # This defines the different columns of the dataset and their types
91
+ features=features, # Here we define them above because they are different between the two configurations
92
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
93
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
94
+ supervised_keys=("png", "layer_mask"),
95
+ # Homepage of the dataset for documentation
96
+ homepage=_HOMEPAGE,
97
+ # License for the dataset if available
98
+ license=_LICENSE,
99
+ # Citation for the dataset
100
+ citation=_CITATION,
101
+ )
102
+
103
+ def _split_generators(self, dl_manager):
104
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
105
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
106
+
107
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
108
+ # 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.
109
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
110
+ if self.config.name == 'mixed':
111
+ urls = _URLS
112
+ else:
113
+ urls = {self.config.name: _URLS[self.config.name]}
114
+
115
+ data_dir = dl_manager.download_and_extract(urls)
116
+ return [
117
+ datasets.SplitGenerator(
118
+ name=datasets.Split.TRAIN,
119
+ # These kwargs will be passed to _generate_examples
120
+ gen_kwargs={
121
+ "data_dir": data_dir,
122
+ "split": "train",
123
+ },
124
+ ),
125
+ datasets.SplitGenerator(
126
+ name=datasets.Split.VALIDATION,
127
+ # These kwargs will be passed to _generate_examples
128
+ gen_kwargs={
129
+ "data_dir": data_dir,
130
+ "split": "dev",
131
+ },
132
+ ),
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TEST,
135
+ # These kwargs will be passed to _generate_examples
136
+ gen_kwargs={
137
+ "data_dir": data_dir,
138
+ "split": "test"
139
+ },
140
+ ),
141
+ ]
142
+
143
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
144
+ def _generate_examples(self, data_dir, split):
145
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
146
+ start, stop = self.SPLIT_COUNTS[split]
147
+ domains = [self.config.name]
148
+
149
+ if self.config.name == 'mixed':
150
+ start = start * 4
151
+ stop = stop * 4
152
+ domains = [
153
+ 'circles',
154
+ 'squares',
155
+ 'squares_and_circles',
156
+ 'scer'
157
+ ]
158
+
159
+ divisions = len(domains)
160
+
161
+ for key in range(start, stop):
162
+ domain = domains[key % divisions]
163
+ idx = floor(key / divisions)
164
+ yield f'{self.config.name}_{str(key).zfill(6)}', \
165
+ self._example_for_domain(data_dir, domain, idx, split)
166
+
167
+
168
+ def _example_for_domain(self, data_dir, domain, idx, split):
169
+ data = {}
170
+ svg_path = os.path.join(data_dir[domain], domain, 'svg', str(idx).zfill(6) + '.svg')
171
+ with open(svg_path, 'r') as file:
172
+ data['svg'] = file.read()
173
+
174
+ png_path = os.path.join(data_dir[domain], domain, 'png', str(idx).zfill(6) + '.png')
175
+ with open(png_path, 'rb') as file:
176
+ data['png'] = {"path": png_path, "bytes": file.read()}
177
+
178
+ if split != "test":
179
+ layer_mask_path = os.path.join(data_dir[domain], domain, 'layer_mask', str(idx).zfill(6) + '.png')
180
+ with open(layer_mask_path, 'rb') as file:
181
+ data['layer_mask'] = {"path": layer_mask_path, "bytes": file.read()}
182
+ object_mask_path = os.path.join(data_dir[domain], domain, 'obj_mask', str(idx).zfill(6) + '.png')
183
+ with open(object_mask_path, 'rb') as file:
184
+ data['object_mask'] = {"path": object_mask_path, "bytes": file.read()}
185
+ else:
186
+ data['layer_mask'] = ''
187
+ data['object_mask'] = ''
188
+ return data