ikanher commited on
Commit
e18a7c9
1 Parent(s): 194f9ee

Delete loading script

Browse files
Files changed (1) hide show
  1. FGVC-Aircraft.py +0 -389
FGVC-Aircraft.py DELETED
@@ -1,389 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors.
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
- """FGVC Aircraft loading script."""
15
-
16
-
17
- import csv
18
- import json
19
- import os
20
- from pathlib import Path
21
-
22
- import datasets
23
-
24
- _CITATION = """\
25
- @techreport{maji13fine-grained,
26
- title = {Fine-Grained Visual Classification of Aircraft},
27
- author = {S. Maji and J. Kannala and E. Rahtu
28
- and M. Blaschko and A. Vedaldi},
29
- year = {2013},
30
- archivePrefix = {arXiv},
31
- eprint = {1306.5151},
32
- primaryClass = "cs-cv",
33
- }
34
- """
35
-
36
- _DESCRIPTION = """\
37
- The dataset contains 10,200 images of aircraft, with 100 images for each of 102 different aircraft model variants, most of which are airplanes. The (main) aircraft in each image is annotated with a tight bounding box and a hierarchical airplane model label.
38
-
39
- Aircraft models are organized in a four-levels hierarchy. The four levels, from finer to coarser, are:
40
-
41
- Model, e.g. Boeing 737-76J. Since certain models are nearly visually indistinguishable, this level is not used in the evaluation.
42
- Variant, e.g. Boeing 737-700. A variant collapses all the models that are visually indistinguishable into one class. The dataset comprises 102 different variants.
43
- Family, e.g. Boeing 737. The dataset comprises 70 different families.
44
- Manufacturer, e.g. Boeing. The dataset comprises 41 different manufacturers.
45
-
46
- The data is divided into three equally-sized training, validation and test subsets. The first two sets can be used for development, and the latter should be used for final evaluation only.
47
- """
48
-
49
- _HOMEPAGE = "https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/"
50
-
51
- _LICENSE = "exclusively for non-commercial research purposes"
52
-
53
- _URL = "https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/archives/fgvc-aircraft-2013b.tar.gz"
54
-
55
-
56
- _FAMILIES = [
57
- "A300",
58
- "A310",
59
- "A320",
60
- "A330",
61
- "A340",
62
- "A380",
63
- "ATR-42",
64
- "ATR-72",
65
- "An-12",
66
- "BAE 146",
67
- "BAE-125",
68
- "Beechcraft 1900",
69
- "Boeing 707",
70
- "Boeing 717",
71
- "Boeing 727",
72
- "Boeing 737",
73
- "Boeing 747",
74
- "Boeing 757",
75
- "Boeing 767",
76
- "Boeing 777",
77
- "C-130",
78
- "C-47",
79
- "CRJ-200",
80
- "CRJ-700",
81
- "Cessna 172",
82
- "Cessna 208",
83
- "Cessna Citation",
84
- "Challenger 600",
85
- "DC-10",
86
- "DC-3",
87
- "DC-6",
88
- "DC-8",
89
- "DC-9",
90
- "DH-82",
91
- "DHC-1",
92
- "DHC-6",
93
- "DR-400",
94
- "Dash 8",
95
- "Dornier 328",
96
- "EMB-120",
97
- "Embraer E-Jet",
98
- "Embraer ERJ 145",
99
- "Embraer Legacy 600",
100
- "Eurofighter Typhoon",
101
- "F-16",
102
- "F/A-18",
103
- "Falcon 2000",
104
- "Falcon 900",
105
- "Fokker 100",
106
- "Fokker 50",
107
- "Fokker 70",
108
- "Global Express",
109
- "Gulfstream",
110
- "Hawk T1",
111
- "Il-76",
112
- "King Air",
113
- "L-1011",
114
- "MD-11",
115
- "MD-80",
116
- "MD-90",
117
- "Metroliner",
118
- "PA-28",
119
- "SR-20",
120
- "Saab 2000",
121
- "Saab 340",
122
- "Spitfire",
123
- "Tornado",
124
- "Tu-134",
125
- "Tu-154",
126
- "Yak-42",
127
- ]
128
-
129
-
130
- _MANUFACTURERS = [
131
- "ATR",
132
- "Airbus",
133
- "Antonov",
134
- "Beechcraft",
135
- "Boeing",
136
- "Bombardier Aerospace",
137
- "British Aerospace",
138
- "Canadair",
139
- "Cessna",
140
- "Cirrus Aircraft",
141
- "Dassault Aviation",
142
- "Dornier",
143
- "Douglas Aircraft Company",
144
- "Embraer",
145
- "Eurofighter",
146
- "Fairchild",
147
- "Fokker",
148
- "Gulfstream Aerospace",
149
- "Ilyushin",
150
- "Lockheed Corporation",
151
- "Lockheed Martin",
152
- "McDonnell Douglas",
153
- "Panavia",
154
- "Piper",
155
- "Robin",
156
- "Saab",
157
- "Supermarine",
158
- "Tupolev",
159
- "Yakovlev",
160
- "de Havilland",
161
- ]
162
-
163
-
164
- _VARIANTS = [
165
- "707-320",
166
- "727-200",
167
- "737-200",
168
- "737-300",
169
- "737-400",
170
- "737-500",
171
- "737-600",
172
- "737-700",
173
- "737-800",
174
- "737-900",
175
- "747-100",
176
- "747-200",
177
- "747-300",
178
- "747-400",
179
- "757-200",
180
- "757-300",
181
- "767-200",
182
- "767-300",
183
- "767-400",
184
- "777-200",
185
- "777-300",
186
- "A300B4",
187
- "A310",
188
- "A318",
189
- "A319",
190
- "A320",
191
- "A321",
192
- "A330-200",
193
- "A330-300",
194
- "A340-200",
195
- "A340-300",
196
- "A340-500",
197
- "A340-600",
198
- "A380",
199
- "ATR-42",
200
- "ATR-72",
201
- "An-12",
202
- "BAE 146-200",
203
- "BAE 146-300",
204
- "BAE-125",
205
- "Beechcraft 1900",
206
- "Boeing 717",
207
- "C-130",
208
- "C-47",
209
- "CRJ-200",
210
- "CRJ-700",
211
- "CRJ-900",
212
- "Cessna 172",
213
- "Cessna 208",
214
- "Cessna 525",
215
- "Cessna 560",
216
- "Challenger 600",
217
- "DC-10",
218
- "DC-3",
219
- "DC-6",
220
- "DC-8",
221
- "DC-9-30",
222
- "DH-82",
223
- "DHC-1",
224
- "DHC-6",
225
- "DHC-8-100",
226
- "DHC-8-300",
227
- "DR-400",
228
- "Dornier 328",
229
- "E-170",
230
- "E-190",
231
- "E-195",
232
- "EMB-120",
233
- "ERJ 135",
234
- "ERJ 145",
235
- "Embraer Legacy 600",
236
- "Eurofighter Typhoon",
237
- "F-16A/B",
238
- "F/A-18",
239
- "Falcon 2000",
240
- "Falcon 900",
241
- "Fokker 100",
242
- "Fokker 50",
243
- "Fokker 70",
244
- "Global Express",
245
- "Gulfstream IV",
246
- "Gulfstream V",
247
- "Hawk T1",
248
- "Il-76",
249
- "L-1011",
250
- "MD-11",
251
- "MD-80",
252
- "MD-87",
253
- "MD-90",
254
- "Metroliner",
255
- "Model B200",
256
- "PA-28",
257
- "SR-20",
258
- "Saab 2000",
259
- "Saab 340",
260
- "Spitfire",
261
- "Tornado",
262
- "Tu-134",
263
- "Tu-154",
264
- "Yak-42",
265
- ]
266
-
267
-
268
- def parse_annotations(annotations, join_labels=True):
269
- annotations = [annotation.strip().split() for annotation in annotations]
270
- if join_labels:
271
- return {
272
- annotation[0].strip(): " ".join(annotation[1:])
273
- for annotation in annotations
274
- }
275
- else:
276
- return {annotation[0].strip(): annotation[1:] for annotation in annotations}
277
-
278
-
279
- class FGVCAircraft(datasets.GeneratorBasedBuilder):
280
-
281
- VERSION = datasets.Version("1.0.0")
282
-
283
- # # This is an example of a dataset with multiple configurations.
284
- # # If you don't want/need to define several sub-sets in your dataset,
285
- # # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
286
-
287
- # # If you need to make complex sub-parts in the datasets with configurable options
288
- # # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
289
- # # BUILDER_CONFIG_CLASS = MyBuilderConfig
290
-
291
- # # You will be able to load one or the other configurations in the following list with
292
- # # data = datasets.load_dataset('my_dataset', 'first_domain')
293
- # # data = datasets.load_dataset('my_dataset', 'second_domain')
294
- # BUILDER_CONFIGS = [
295
- # datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
296
- # datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
297
- # ]
298
-
299
- # DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
300
-
301
- def _info(self):
302
- features = datasets.Features(
303
- {
304
- "image": datasets.Image(),
305
- "bbox": {
306
- "ymin": datasets.features.Value(dtype="int64"),
307
- "xmin": datasets.features.Value(dtype="int64"),
308
- "ymax": datasets.features.Value(dtype="int64"),
309
- "xmax": datasets.features.Value(dtype="int64"),
310
- },
311
- "family": datasets.features.ClassLabel(names=_FAMILIES),
312
- "manufacturer": datasets.features.ClassLabel(names=_MANUFACTURERS),
313
- "variant": datasets.features.ClassLabel(names=_VARIANTS),
314
- }
315
- )
316
- return datasets.DatasetInfo(
317
- description=_DESCRIPTION,
318
- features=features,
319
- homepage=_HOMEPAGE,
320
- license=_LICENSE,
321
- citation=_CITATION,
322
- )
323
-
324
- def _split_generators(self, dl_manager):
325
- data_dir = dl_manager.download_and_extract(_URL)
326
- data_dir = Path(data_dir) / "fgvc-aircraft-2013b" / "data"
327
- return [
328
- datasets.SplitGenerator(
329
- name=datasets.Split.TRAIN,
330
- gen_kwargs={
331
- "images_dir": data_dir / "images",
332
- "annotations_dir": data_dir,
333
- "split": "train",
334
- },
335
- ),
336
- datasets.SplitGenerator(
337
- name=datasets.Split.VALIDATION,
338
- gen_kwargs={
339
- "images_dir": data_dir / "images",
340
- "annotations_dir": data_dir,
341
- "split": "val",
342
- },
343
- ),
344
- datasets.SplitGenerator(
345
- name=datasets.Split.TEST,
346
- gen_kwargs={
347
- "images_dir": data_dir / "images",
348
- "annotations_dir": data_dir,
349
- "split": "test",
350
- },
351
- ),
352
- ]
353
-
354
- def _generate_examples(self, images_dir, annotations_dir, split):
355
- image_ids = open(annotations_dir / f"images_{split}.txt").readlines()
356
- image_ids = [image_id.strip() for image_id in image_ids]
357
-
358
- families = open(annotations_dir / f"images_family_{split}.txt").readlines()
359
- families = parse_annotations(families)
360
-
361
- manufacturers = open(
362
- annotations_dir / f"images_manufacturer_{split}.txt"
363
- ).readlines()
364
- manufacturers = parse_annotations(manufacturers)
365
-
366
- variants = open(annotations_dir / f"images_variant_{split}.txt").readlines()
367
- variants = parse_annotations(variants)
368
-
369
- bounding_boxes = open(
370
- os.path.join(annotations_dir, "images_box.txt")
371
- ).readlines()
372
-
373
- bounding_boxes = parse_annotations(bounding_boxes, join_labels=False)
374
-
375
- for image_id in image_ids:
376
- full_path = images_dir / f"{image_id}.jpg"
377
- family = families[image_id]
378
- manufacturer = manufacturers[image_id]
379
- variant = variants[image_id]
380
- xmin, ymin, xmax, ymax = list(map(int, bounding_boxes[image_id]))
381
-
382
- record = {
383
- "image": str(full_path),
384
- "bbox": {"ymin": ymin, "xmin": xmin, "ymax": ymax, "xmax": xmax},
385
- "family": family,
386
- "manufacturer": manufacturer,
387
- "variant": variant,
388
- }
389
- yield image_id, record