Zihao commited on
Commit
1baba94
·
1 Parent(s): 8bbf637
Files changed (1) hide show
  1. zhlds.py +739 -30
zhlds.py CHANGED
@@ -39,6 +39,14 @@ Note that each ELEVATER dataset has its own citation. Please see the source to
39
  get the correct citation for each contained dataset.
40
  """
41
 
 
 
 
 
 
 
 
 
42
  _VOC_2007_CLASSIFICATION_CITATION="""\
43
  @misc{pascal-voc-2007,
44
  author = "Everingham, M. and Van~Gool, L. and Williams, C. K. I. and Winn, J. and Zisserman, A.",
@@ -46,7 +54,80 @@ _VOC_2007_CLASSIFICATION_CITATION="""\
46
  howpublished = "http://www.pascal-network.org/challenges/VOC/voc2007/workshop/index.html"
47
  }"""
48
 
49
- _CIFAR_10_CITATION="""\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  @article{krizhevsky2009learning,
51
  title={Learning multiple layers of features from tiny images},
52
  author={Krizhevsky, Alex and Hinton, Geoffrey and others},
@@ -54,10 +135,108 @@ _CIFAR_10_CITATION="""\
54
  publisher={Toronto, ON, Canada}
55
  }"""
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  class ELEVATERConfig(datasets.BuilderConfig):
58
 
59
  """BuilderConfig for ELEVATER."""
60
- def __init__(self, name, description, contact, version, type_, root_folder, labelmap, num_classes, train, test, citation, url, **kwargs):
 
61
  """BuilderConfig for ELEVATER.
62
  Args:
63
  features: `list[string]`, list of the features that will appear in the
@@ -76,10 +255,12 @@ class ELEVATERConfig(datasets.BuilderConfig):
76
  self.contact = contact
77
  self.version = version
78
  self.type = type_
 
79
  self.root_folder = root_folder
80
  self.labelmap = labelmap
81
  self.num_classes = num_classes
82
  self.train = train
 
83
  self.test = test
84
  self.citation = citation
85
  self.url = url
@@ -94,6 +275,7 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
94
  contact="pinjin",
95
  version=_VERSION,
96
  type_="classification_multiclass",
 
97
  root_folder="classification/cifar_10_20211007",
98
  labelmap="labels.txt",
99
  num_classes=10,
@@ -102,6 +284,7 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
102
  "files_for_local_usage": ["train.zip"],
103
  "num_images": 50000
104
  },
 
105
  test={
106
  "index_path": "test.txt",
107
  "files_for_local_usage": ["val.zip"],
@@ -115,7 +298,8 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
115
  description="Voc2007 classification dataset.",
116
  contact="pinjin",
117
  version=_VERSION,
118
- type="classification_multilabel",
 
119
  root_folder="classification/voc2007_20211007",
120
  train={
121
  "index_path": "train_ic.txt",
@@ -136,17 +320,502 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
136
  num_classes=20,
137
  citation=_VOC_2007_CLASSIFICATION_CITATION,
138
  url=_BASE_URL,
139
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  ]
141
 
142
  def _info(self):
143
- features = datasets.Features(
144
- {
145
- "image_file_path": datasets.Value("string"),
146
- "image": datasets.Image(),
147
- "labels": datasets.Value("int32")
148
- }
149
- )
 
 
 
 
 
 
 
 
 
150
  return datasets.DatasetInfo(
151
  description=self.config.description,
152
  features=features,
@@ -155,10 +824,7 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
155
 
156
  def _split_generators(self, dl_manager):
157
  _URL = self.config.url + self.config.root_folder
158
- print(self.config.val)
159
- print(good)
160
  urls_to_download = {
161
- "labelmap": os.path.join(_URL, self.config.labelmap),
162
  "train": {
163
  "images": os.path.join(_URL, self.config.train['files_for_local_usage'][0]),
164
  "index": os.path.join(_URL, self.config.train['index_path']),
@@ -168,9 +834,15 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
168
  "index": os.path.join(_URL, self.config.test['index_path']),
169
  }
170
  }
 
 
 
 
 
 
171
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
172
 
173
- return [
174
  datasets.SplitGenerator(
175
  name=datasets.Split.TRAIN,
176
  gen_kwargs={
@@ -186,20 +858,57 @@ class ELEVATER(datasets.GeneratorBasedBuilder):
186
  "index": downloaded_files["test"]["index"],
187
  "split": datasets.Split.TEST,
188
  },
189
- )
190
- ]
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  def _generate_examples(self, images, index, split):
193
- image_path_label_list = []
194
- with open(index, "r") as f:
195
- lines = f.readlines()
196
- for i, line in enumerate(lines):
197
- line_split = line[:-1].split(" ")
198
- label = int(line_split[1])
199
- image_path = line_split[0].split('@')[1]
200
- path = images + '/' + image_path
201
- yield i, {
202
- "image_file_path": path,
203
- "image": path,
204
- "labels": label,
205
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  get the correct citation for each contained dataset.
40
  """
41
 
42
+ _CIFAR_10_CITATION="""\
43
+ @article{krizhevsky2009learning,
44
+ title={Learning multiple layers of features from tiny images},
45
+ author={Krizhevsky, Alex and Hinton, Geoffrey and others},
46
+ year={2009},
47
+ publisher={Toronto, ON, Canada}
48
+ }"""
49
+
50
  _VOC_2007_CLASSIFICATION_CITATION="""\
51
  @misc{pascal-voc-2007,
52
  author = "Everingham, M. and Van~Gool, L. and Williams, C. K. I. and Winn, J. and Zisserman, A.",
 
54
  howpublished = "http://www.pascal-network.org/challenges/VOC/voc2007/workshop/index.html"
55
  }"""
56
 
57
+ _GTSRB_CITATION="""\
58
+ @inproceedings{Houben-IJCNN-2013,
59
+ author = {Sebastian Houben and Johannes Stallkamp and Jan Salmen and Marc Schlipsing and Christian Igel},
60
+ booktitle = {International Joint Conference on Neural Networks},
61
+ title = {Detection of Traffic Signs in Real-World Images: The {G}erman {T}raffic {S}ign {D}etection {B}enchmark},
62
+ number = {1288},
63
+ year = {2013},
64
+ }"""
65
+
66
+ _COUNTRY211_CITATION="""\
67
+ @inproceedings{radford2021learning,
68
+ title={Learning transferable visual models from natural language supervision},
69
+ author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and Ramesh, Aditya and Goh, Gabriel and Agarwal, Sandhini and Sastry, Girish and Askell, Amanda and Mishkin, Pamela and Clark, Jack and others},
70
+ booktitle={International Conference on Machine Learning},
71
+ pages={8748--8763},
72
+ year={2021},
73
+ organization={PMLR}
74
+ }"""
75
+
76
+ _RENDERED_SST2_CITATION="""\
77
+ @inproceedings{radford2021learning,
78
+ title={Learning transferable visual models from natural language supervision},
79
+ author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and Ramesh, Aditya and Goh, Gabriel and Agarwal, Sandhini and Sastry, Girish and Askell, Amanda and Mishkin, Pamela and Clark, Jack and others},
80
+ booktitle={International Conference on Machine Learning},
81
+ pages={8748--8763},
82
+ year={2021},
83
+ organization={PMLR}
84
+ }"""
85
+
86
+ _KITTI_DISTANCE_CITATION="""\
87
+ @inproceedings{fritsch2013new,
88
+ title={A new performance measure and evaluation benchmark for road detection algorithms},
89
+ author={Fritsch, Jannik and Kuehnl, Tobias and Geiger, Andreas},
90
+ booktitle={16th International IEEE Conference on Intelligent Transportation Systems (ITSC 2013)},
91
+ pages={1693--1700},
92
+ year={2013},
93
+ organization={IEEE}
94
+ }"""
95
+
96
+ _EOROSAT_CLIP_CITATION="""\
97
+ @article{helber2019eurosat,
98
+ title={Eurosat: A novel dataset and deep learning benchmark for land use and land cover classification},
99
+ author={Helber, Patrick and Bischke, Benjamin and Dengel, Andreas and Borth, Damian},
100
+ journal={IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing},
101
+ volume={12},
102
+ number={7},
103
+ pages={2217--2226},
104
+ year={2019},
105
+ publisher={IEEE}
106
+ }"""
107
+
108
+ _RESISC45_CLIP_CITATION="""\
109
+ @article{cheng2017remote,
110
+ title={Remote sensing image scene classification: Benchmark and state of the art},
111
+ author={Cheng, Gong and Han, Junwei and Lu, Xiaoqiang},
112
+ journal={Proceedings of the IEEE},
113
+ volume={105},
114
+ number={10},
115
+ pages={1865--1883},
116
+ year={2017},
117
+ publisher={IEEE}
118
+ }"""
119
+
120
+ _CALTECH_101_CITATION="""\
121
+ @inproceedings{fei2004learning,
122
+ title={Learning generative visual models from few training examples: An incremental bayesian approach tested on 101 object categories},
123
+ author={Fei-Fei, Li and Fergus, Rob and Perona, Pietro},
124
+ booktitle={2004 conference on computer vision and pattern recognition workshop},
125
+ pages={178--178},
126
+ year={2004},
127
+ organization={IEEE}
128
+ }"""
129
+
130
+ _CIFAR_100_CITATION="""\
131
  @article{krizhevsky2009learning,
132
  title={Learning multiple layers of features from tiny images},
133
  author={Krizhevsky, Alex and Hinton, Geoffrey and others},
 
135
  publisher={Toronto, ON, Canada}
136
  }"""
137
 
138
+ _DTD_CITATION="""\
139
+ @inproceedings{cimpoi2014describing,
140
+ title={Describing textures in the wild},
141
+ author={Cimpoi, Mircea and Maji, Subhransu and Kokkinos, Iasonas and Mohamed, Sammy and Vedaldi, Andrea},
142
+ booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
143
+ pages={3606--3613},
144
+ year={2014}
145
+ }"""
146
+
147
+ _FGVC_AIRCRAFT_2013B_VARIANTS102_CITATION="""\
148
+ @article{maji2013fine,
149
+ title={Fine-grained visual classification of aircraft},
150
+ author={Maji, Subhransu and Rahtu, Esa and Kannala, Juho and Blaschko, Matthew and Vedaldi, Andrea},
151
+ journal={arXiv preprint arXiv:1306.5151},
152
+ year={2013}
153
+ }"""
154
+
155
+ _FOOD_101_CITATION="""\
156
+ @inproceedings{bossard2014food,
157
+ title={Food-101--mining discriminative components with random forests},
158
+ author={Bossard, Lukas and Guillaumin, Matthieu and Gool, Luc Van},
159
+ booktitle={European conference on computer vision},
160
+ pages={446--461},
161
+ year={2014},
162
+ organization={Springer}
163
+ }"""
164
+
165
+ _MNIST_CITATION="""\
166
+ @article{deng2012mnist,
167
+ title={The mnist database of handwritten digit images for machine learning research [best of the web]},
168
+ author={Deng, Li},
169
+ journal={IEEE signal processing magazine},
170
+ volume={29},
171
+ number={6},
172
+ pages={141--142},
173
+ year={2012},
174
+ publisher={IEEE}
175
+ }"""
176
+
177
+ _OXFORD_FLOWER_102_CITATION="""\
178
+ @inproceedings{nilsback2008automated,
179
+ title={Automated flower classification over a large number of classes},
180
+ author={Nilsback, Maria-Elena and Zisserman, Andrew},
181
+ booktitle={2008 Sixth Indian Conference on Computer Vision, Graphics \& Image Processing},
182
+ pages={722--729},
183
+ year={2008},
184
+ organization={IEEE}
185
+ }"""
186
+
187
+ _OXFORD_IIIT_PETS_CITATION="""\
188
+ @inproceedings{parkhi2012cats,
189
+ title={Cats and dogs},
190
+ author={Parkhi, Omkar M and Vedaldi, Andrea and Zisserman, Andrew and Jawahar, CV},
191
+ booktitle={2012 IEEE conference on computer vision and pattern recognition},
192
+ pages={3498--3505},
193
+ year={2012},
194
+ organization={IEEE}
195
+ }"""
196
+
197
+ _PATCH_CAMELYON_CITATION="""\
198
+ @inproceedings{veeling2018rotation,
199
+ title={Rotation equivariant CNNs for digital pathology},
200
+ author={Veeling, Bastiaan S and Linmans, Jasper and Winkens, Jim and Cohen, Taco and Welling, Max},
201
+ booktitle={International Conference on Medical image computing and computer-assisted intervention},
202
+ pages={210--218},
203
+ year={2018},
204
+ organization={Springer}
205
+ }"""
206
+
207
+ _STANFORD_CARS_CITATION="""\
208
+ @inproceedings{krause20133d,
209
+ title={3d object representations for fine-grained categorization},
210
+ author={Krause, Jonathan and Stark, Michael and Deng, Jia and Fei-Fei, Li},
211
+ booktitle={Proceedings of the IEEE international conference on computer vision workshops},
212
+ pages={554--561},
213
+ year={2013}
214
+ }"""
215
+
216
+ _FER_2013_CITATION="""\
217
+ @misc{challenges-in-representation-learning-facial-expression-recognition-challenge,
218
+ author = {Dumitru, Ian Goodfellow, Yoshua Bengio},
219
+ title = {Challenges in Representation Learning: Facial Expression Recognition Challenge},
220
+ publisher = {Kaggle},
221
+ year = {2013},
222
+ url = {https://kaggle.com/competitions/challenges-in-representation-learning-facial-expression-recognition-challenge}
223
+ }"""
224
+
225
+ _HATEFUL_MEMES_CITATION="""\
226
+ @article{kiela2020hateful,
227
+ title={The hateful memes challenge: Detecting hate speech in multimodal memes},
228
+ author={Kiela, Douwe and Firooz, Hamed and Mohan, Aravind and Goswami, Vedanuj and Singh, Amanpreet and Ringshia, Pratik and Testuggine, Davide},
229
+ journal={Advances in Neural Information Processing Systems},
230
+ volume={33},
231
+ pages={2611--2624},
232
+ year={2020}
233
+ }"""
234
+
235
  class ELEVATERConfig(datasets.BuilderConfig):
236
 
237
  """BuilderConfig for ELEVATER."""
238
+ def __init__(self, name, description, contact, version, type_, format_,
239
+ root_folder, labelmap, num_classes, train, val, test, citation, url, **kwargs):
240
  """BuilderConfig for ELEVATER.
241
  Args:
242
  features: `list[string]`, list of the features that will appear in the
 
255
  self.contact = contact
256
  self.version = version
257
  self.type = type_
258
+ self.format = format_
259
  self.root_folder = root_folder
260
  self.labelmap = labelmap
261
  self.num_classes = num_classes
262
  self.train = train
263
+ self.val = val
264
  self.test = test
265
  self.citation = citation
266
  self.url = url
 
275
  contact="pinjin",
276
  version=_VERSION,
277
  type_="classification_multiclass",
278
+ format_=None,
279
  root_folder="classification/cifar_10_20211007",
280
  labelmap="labels.txt",
281
  num_classes=10,
 
284
  "files_for_local_usage": ["train.zip"],
285
  "num_images": 50000
286
  },
287
+ val=None,
288
  test={
289
  "index_path": "test.txt",
290
  "files_for_local_usage": ["val.zip"],
 
298
  description="Voc2007 classification dataset.",
299
  contact="pinjin",
300
  version=_VERSION,
301
+ type_="classification_multilabel",
302
+ format_=None,
303
  root_folder="classification/voc2007_20211007",
304
  train={
305
  "index_path": "train_ic.txt",
 
320
  num_classes=20,
321
  citation=_VOC_2007_CLASSIFICATION_CITATION,
322
  url=_BASE_URL,
323
+ ),
324
+ ELEVATERConfig(
325
+ name="gtsrb",
326
+ description="The German Traffic Sign Recognition Benchmark (GTSRB) is a multi-class image classification benchmark in the domain of advanced driver assistance systems and autonomous driving. It was first published at IJCNN 2011.",
327
+ contact=None,
328
+ version=_VERSION,
329
+ type_="classification_multiclass",
330
+ format_=None,
331
+ root_folder="classification/gtsrb_20210923",
332
+ train={
333
+ "index_path": "train.txt",
334
+ "files_for_local_usage": ["train.zip"],
335
+ "num_images": 26640
336
+ },
337
+ val={
338
+ "index_path": "val.txt",
339
+ "files_for_local_usage": ["val.zip"],
340
+ "num_images": 12569
341
+ },
342
+ test={
343
+ "index_path": "test.txt",
344
+ "files_for_local_usage": ["final_test.zip"],
345
+ "num_images": 12630
346
+ },
347
+ labelmap="labelmap.txt",
348
+ num_classes=43,
349
+ citation=_GTSRB_CITATION,
350
+ url=_BASE_URL,
351
+ ),
352
+ ELEVATERConfig(
353
+ name="country211",
354
+ description="Country211 is an internal OpenAI dataset designed to assess the geolocation capability of visual representations. It filters the YFCC100m dataset (Thomee et al., 2016) to find 211 countries (defined as having an ISO-3166 country code) that have at least 300 photos with GPS coordinates. OpenAI built a balanced dataset with 211 categories, by sampling 200 photos for training and 100 photos for testing, for each country.",
355
+ contact=None,
356
+ version=_VERSION,
357
+ type_="classification_multiclass",
358
+ format_=None,
359
+ root_folder="classification/country211_20210924",
360
+ train={
361
+ "index_path": "train.txt",
362
+ "files_for_local_usage": ["train.zip"],
363
+ "num_images": 31650
364
+ },
365
+ val={
366
+ "index_path": "valid.txt",
367
+ "files_for_local_usage": ["valid.zip"],
368
+ "num_images": 10550
369
+ },
370
+ test={
371
+ "index_path": "test.txt",
372
+ "files_for_local_usage": ["test.zip"],
373
+ "num_images": 21100
374
+ },
375
+ labelmap="labels.txt",
376
+ num_classes=211,
377
+ citation=_COUNTRY211_CITATION,
378
+ url=_BASE_URL,
379
+ ),
380
+ ELEVATERConfig(
381
+ name="rendered-sst2",
382
+ description="Dataset is from CLIP: The Rendered SST2 dataset is designed to measure the optical character recognition capability of visual representations. To do so, we used the sentences from the Stanford Sentiment Treebank dataset (Socher et al., 2013) and rendered them into images, with black texts on a white background, in a 448×448 resolution.",
383
+ contact=None,
384
+ version=_VERSION,
385
+ type_="classification_multiclass",
386
+ format_=None,
387
+ root_folder="classification/rendered_sst2_20210924",
388
+ train={
389
+ "index_path": "train.txt",
390
+ "files_for_local_usage": ["train.zip"],
391
+ "num_images": 6920
392
+ },
393
+ val={
394
+ "index_path": "valid.txt",
395
+ "files_for_local_usage": ["valid.zip"],
396
+ "num_images": 827
397
+ },
398
+ test={
399
+ "index_path": "test.txt",
400
+ "files_for_local_usage": ["test.zip"],
401
+ "num_images": 1821
402
+ },
403
+ labelmap="labels.txt",
404
+ num_classes=2,
405
+ citation=_RENDERED_SST2_CITATION,
406
+ url=_BASE_URL,
407
+ ),
408
+ ELEVATERConfig(
409
+ name="kitti-distance",
410
+ description="The kitti-distance dataset was taken from the VTAB benchmark, and the task was to predict how distant a vehicle is in the photo. More details: https://github.com/openai/CLIP/issues/86",
411
+ contact=None,
412
+ version=_VERSION,
413
+ type_="classification_multiclass",
414
+ format_="coco",
415
+ root_folder="classification/kitti_distance_20210923",
416
+ train={
417
+ "index_path": "train_meta.json",
418
+ "files_for_local_usage": ["train_images.zip"],
419
+ "num_images": 6347
420
+ },
421
+ val={
422
+ "index_path": "validation_meta.json",
423
+ "files_for_local_usage": ["validation_images.zip"],
424
+ "num_images": 423
425
+ },
426
+ test={
427
+ "index_path": "test_meta.json",
428
+ "files_for_local_usage": ["test_images.zip"],
429
+ "num_images": 711
430
+ },
431
+ labelmap=None,
432
+ num_classes=4,
433
+ citation=_KITTI_DISTANCE_CITATION,
434
+ url=_BASE_URL,
435
+ ),
436
+ ELEVATERConfig(
437
+ name="eurosat_clip",
438
+ description="Dataset sampled by CLIP from Eurosat (EuroSAT dataset is based on Sentinel-2 satellite images covering 13 spectral bands and consisting of 10 classes with 27000 labeled and geo-referenced samples.), see: https://github.com/openai/CLIP/issues/45",
439
+ contact=None,
440
+ version=_VERSION,
441
+ type_="classification_multiclass",
442
+ format_=None,
443
+ root_folder="classification/eurosat_clip_20210930",
444
+ train={
445
+ "index_path": "train.txt",
446
+ "files_for_local_usage": ["2750.zip"],
447
+ "num_images": 5000
448
+ },
449
+ val={
450
+ "index_path": "val.txt",
451
+ "files_for_local_usage": ["2750.zip"],
452
+ "num_images": 5000
453
+ },
454
+ test={
455
+ "index_path": "test.txt",
456
+ "files_for_local_usage": ["2750.zip"],
457
+ "num_images": 5000
458
+ },
459
+ labelmap="labels.txt",
460
+ num_classes=10,
461
+ citation=_EOROSAT_CLIP_CITATION,
462
+ url=_BASE_URL,
463
+ ),
464
+ ELEVATERConfig(
465
+ name="resisc45_clip",
466
+ description="Dataset sampled by CLIP, see: https://github.com/openai/CLIP/issues/45. RESISC45 dataset is a publicly available benchmark for Remote Sensing Image Scene Classification",
467
+ contact=None,
468
+ version=_VERSION,
469
+ type_="classification_multiclass",
470
+ format_="coco",
471
+ root_folder="classification/resisc45_clip_20210924",
472
+ train={
473
+ "index_path": "train.json",
474
+ "files_for_local_usage": ["images.zip"],
475
+ "num_images": 3150
476
+ },
477
+ val={
478
+ "index_path": "val.json",
479
+ "files_for_local_usage": ["images.zip"],
480
+ "num_images": 3150
481
+ },
482
+ test={
483
+ "index_path": "test.json",
484
+ "files_for_local_usage": ["images.zip"],
485
+ "num_images": 25200
486
+ },
487
+ labelmap="labels.txt",
488
+ num_classes=45,
489
+ citation=_RESISC45_CLIP_CITATION,
490
+ url=_BASE_URL,
491
+ ),
492
+ ELEVATERConfig(
493
+ name="caltech-101",
494
+ description="Pictures of objects belonging to 101 categories. About 40 to 800 images per category. Most categories have about 50 images. Collected in September 2003 by Fei-Fei Li, Marco Andreetto, and Marc 'Aurelio Ranzato. The size of each image is roughly 300 x 200 pixels. ",
495
+ contact="pinjin",
496
+ version=_VERSION,
497
+ type_="classification_multiclass",
498
+ format_=None,
499
+ root_folder="classification/caltech_101_20211007",
500
+ train={
501
+ "index_path": "train.txt",
502
+ "files_for_local_usage": ["train.zip"],
503
+ "num_images": 3060
504
+ },
505
+ val=None,
506
+ test={
507
+ "index_path": "test.txt",
508
+ "files_for_local_usage": ["test.zip"],
509
+ "num_images": 6084
510
+ },
511
+ labelmap=None,
512
+ num_classes=45,
513
+ citation=_CALTECH_101_CITATION,
514
+ url=_BASE_URL,
515
+ ),
516
+ ELEVATERConfig(
517
+ name="cifar-100",
518
+ description="This dataset is just like the CIFAR-10, except it has 100 classes containing 600 images each. There are 500 training images and 100 testing images per class. The 100 classes in the CIFAR-100 are grouped into 20 superclasses. Each image comes with a 'fine' label (the class to which it belongs) and a 'coarse' label (the superclass to which it belongs).",
519
+ contact="pinjin",
520
+ version=_VERSION,
521
+ type_="classification_multiclass",
522
+ format_=None,
523
+ root_folder="classification/cifar100_20200721",
524
+ train={
525
+ "index_path": "train_images.txt",
526
+ "files_for_local_usage": ["train_images.zip"],
527
+ "num_images": 50000
528
+ },
529
+ val=None,
530
+ test={
531
+ "index_path": "test_images.txt",
532
+ "files_for_local_usage": ["test_images.zip"],
533
+ "num_images": 10000
534
+ },
535
+ labelmap="labels.txt",
536
+ num_classes=100,
537
+ citation=_CIFAR_100_CITATION,
538
+ url=_BASE_URL,
539
+ ),
540
+ ELEVATERConfig(
541
+ name="dtd",
542
+ description="The Describable Textures Dataset (DTD) is an evolving collection of textural images in the wild, annotated with a series of human-centric attributes, inspired by the perceptual properties of textures. This data is made available to the computer vision community for research purposes.",
543
+ contact="pinjin",
544
+ version=_VERSION,
545
+ type_="classification_multiclass",
546
+ format_=None,
547
+ root_folder="classification/dtd_20211007",
548
+ train={
549
+ "index_path": "train.txt",
550
+ "files_for_local_usage": ["train.zip"],
551
+ "num_images": 1880
552
+ },
553
+ val={
554
+ "index_path": "val.txt",
555
+ "files_for_local_usage": ["val.zip"],
556
+ "num_images": 1880
557
+ },
558
+ test={
559
+ "index_path": "test.txt",
560
+ "files_for_local_usage": ["test.zip"],
561
+ "num_images": 1880
562
+ },
563
+ labelmap="labels.txt",
564
+ num_classes=47,
565
+ citation=_DTD_CITATION,
566
+ url=_BASE_URL,
567
+ ),
568
+ ELEVATERConfig(
569
+ name="fgvc-aircraft-2013b-variants102",
570
+ description="Fine-Grained Visual Classification of Aircraft (FGVC-Aircraft) is a benchmark dataset for the fine grained visual categorization of aircraft.",
571
+ contact="pinjin",
572
+ version=_VERSION,
573
+ type_="classification_multiclass",
574
+ format_=None,
575
+ root_folder="classification/fgvc_aircraft_2013b_variants102_20211007",
576
+ train={
577
+ "index_path": "train.txt",
578
+ "files_for_local_usage": ["train.zip"],
579
+ "num_images": 3334
580
+ },
581
+ val={
582
+ "index_path": "val.txt",
583
+ "files_for_local_usage": ["val.zip"],
584
+ "num_images": 3333
585
+ },
586
+ test={
587
+ "index_path": "test.txt",
588
+ "files_for_local_usage": ["test.zip"],
589
+ "num_images": 3333
590
+ },
591
+ labelmap="labels.txt",
592
+ num_classes=100,
593
+ citation=_FGVC_AIRCRAFT_2013B_VARIANTS102_CITATION,
594
+ url=_BASE_URL,
595
+ ),
596
+ ELEVATERConfig(
597
+ name="food-101",
598
+ description="This dataset consists of 101 food categories, with 101000 images. For each class, 250 manually reviewed test images are provided as well as 750 training images. On purpose, the training images were not cleaned, and thus still contain some amount of noise. This comes mostly in the form of intense colors and sometimes wrong labels. All images were rescaled to have a maximum side length of 512 pixels.",
599
+ contact="pinjin",
600
+ version=_VERSION,
601
+ type_="classification_multiclass",
602
+ format_=None,
603
+ root_folder="classification/food_101_20211007",
604
+ train={
605
+ "index_path": "train.txt",
606
+ "files_for_local_usage": ["train.zip"],
607
+ "num_images": 75750
608
+ },
609
+ val=None,
610
+ test={
611
+ "index_path": "test.txt",
612
+ "files_for_local_usage": ["val.zip"],
613
+ "num_images": 25250
614
+ },
615
+ labelmap="labels.txt",
616
+ num_classes=101,
617
+ citation=_FOOD_101_CITATION,
618
+ url=_BASE_URL,
619
+ ),
620
+ ELEVATERConfig(
621
+ name="mnist",
622
+ description="The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image.",
623
+ contact="pinjin",
624
+ version=_VERSION,
625
+ type_="classification_multiclass",
626
+ format_=None,
627
+ root_folder="classification/mnist_20211008",
628
+ train={
629
+ "index_path": "train.txt",
630
+ "files_for_local_usage": ["train.zip"],
631
+ "num_images": 60000
632
+ },
633
+ val=None,
634
+ test={
635
+ "index_path": "test.txt",
636
+ "files_for_local_usage": ["val.zip"],
637
+ "num_images": 10000
638
+ },
639
+ labelmap="labels.txt",
640
+ num_classes=10,
641
+ citation=_MNIST_CITATION,
642
+ url=_BASE_URL,
643
+ ),
644
+ ELEVATERConfig(
645
+ name="oxford-flower-102",
646
+ description="A dataset consisting of 102 flower categories. The flowers chosen to be flower commonly occuring in the United Kingdom. Each class consists of between 40 and 258 images.",
647
+ contact="pinjin",
648
+ version=_VERSION,
649
+ type_="classification_multiclass",
650
+ format_=None,
651
+ root_folder="classification/oxford_flower_102_20211007",
652
+ train={
653
+ "index_path": "train.txt",
654
+ "files_for_local_usage": ["train.zip"],
655
+ "num_images": 1020
656
+ },
657
+ val={
658
+ "index_path": "val.txt",
659
+ "files_for_local_usage": ["val.zip"],
660
+ "num_images": 1020
661
+ },
662
+ test={
663
+ "index_path": "test.txt",
664
+ "files_for_local_usage": ["test.zip"],
665
+ "num_images": 6149
666
+ },
667
+ labelmap="labels.txt",
668
+ num_classes=102,
669
+ citation=_OXFORD_FLOWER_102_CITATION,
670
+ url=_BASE_URL,
671
+ ),
672
+ ELEVATERConfig(
673
+ name="oxford-iiit-pets",
674
+ description="A 37-category pet dataset with roughly 200 images for each class. The images have a large variations in scale, pose and lighting.",
675
+ contact="pinjin",
676
+ version=_VERSION,
677
+ type_="classification_multiclass",
678
+ format_=None,
679
+ root_folder="classification/oxford_iiit_pets_20211007",
680
+ train={
681
+ "index_path": "train.txt",
682
+ "files_for_local_usage": ["train.zip"],
683
+ "num_images": 3680
684
+ },
685
+ val=None,
686
+ test={
687
+ "index_path": "test.txt",
688
+ "files_for_local_usage": ["val.zip"],
689
+ "num_images": 3669
690
+ },
691
+ labelmap="labels.txt",
692
+ num_classes=37,
693
+ citation=_OXFORD_IIIT_PETS_CITATION,
694
+ url=_BASE_URL,
695
+ ),
696
+ ELEVATERConfig(
697
+ name="patch-camelyon",
698
+ description="The PatchCamelyon benchmark is a new and challenging image classification dataset. It consists of 327.680 color images (96 x 96px) extracted from histopathologic scans of lymph node sections. Each image is annoted with a binary label indicating presence of metastatic tissue. PCam provides a new benchmark for machine learning models: bigger than CIFAR10, smaller than imagenet, trainable on a single GPU.",
699
+ contact="pinjin",
700
+ version=_VERSION,
701
+ type_="classification_multiclass",
702
+ format_=None,
703
+ root_folder="classification/patch_camelyon_20211007",
704
+ train={
705
+ "index_path": "train.txt",
706
+ "files_for_local_usage": ["train.zip"],
707
+ "num_images": 262144
708
+ },
709
+ val={
710
+ "index_path": "val.txt",
711
+ "files_for_local_usage": ["validation.zip"],
712
+ "num_images": 32768
713
+ },
714
+ test={
715
+ "index_path": "test.txt",
716
+ "files_for_local_usage": ["test.zip"],
717
+ "num_images": 32768
718
+ },
719
+ labelmap="labels.txt",
720
+ num_classes=2,
721
+ citation=_PATCH_CAMELYON_CITATION,
722
+ url=_BASE_URL,
723
+ ),
724
+ ELEVATERConfig(
725
+ name="stanford-cars",
726
+ description="The Cars dataset contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images, where each class has been split roughly in a 50-50 split. Classes are typically at the level of Make, Model, Year, e.g. 2012 Tesla Model S or 2012 BMW M3 coupe.",
727
+ contact="pinjin",
728
+ version=_VERSION,
729
+ type_="classification_multiclass",
730
+ format_=None,
731
+ root_folder="classification/stanford_cars_20211007",
732
+ train={
733
+ "index_path": "train.txt",
734
+ "files_for_local_usage": ["train.zip"],
735
+ "num_images": 8144
736
+ },
737
+ val=None,
738
+ test={
739
+ "index_path": "test.txt",
740
+ "files_for_local_usage": ["val.zip"],
741
+ "num_images": 8041
742
+ },
743
+ labelmap="labels.txt",
744
+ num_classes=196,
745
+ citation=_STANFORD_CARS_CITATION,
746
+ url=_BASE_URL,
747
+ ),
748
+ ELEVATERConfig(
749
+ name="fer-2013",
750
+ description="The data consists of 48x48 pixel grayscale images of faces. The task is to categorize each face based on the emotion shown in the facial expression into one of seven categories (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral).",
751
+ contact="pinjin",
752
+ version=_VERSION,
753
+ type_="classification_multiclass",
754
+ format_=None,
755
+ root_folder="classification/fer_2013_20211008",
756
+ train={
757
+ "index_path": "train.txt",
758
+ "files_for_local_usage": ["train.zip"],
759
+ "num_images": 28709
760
+ },
761
+ val={
762
+ "index_path": "val.txt",
763
+ "files_for_local_usage": ["val.zip"],
764
+ "num_images": 3589
765
+ },
766
+ test={
767
+ "index_path": "test.txt",
768
+ "files_for_local_usage": ["test.zip"],
769
+ "num_images": 3589
770
+ },
771
+ labelmap="labels.txt",
772
+ num_classes=7,
773
+ citation=_FER_2013_CITATION,
774
+ url=_BASE_URL,
775
+ ),
776
+ ELEVATERConfig(
777
+ name="hateful-memes",
778
+ description="At the massive scale of the internet, the task of detecting multimodal hate is both extremely important and particularly difficult. Relying on just text or just images to determine whether a meme is hateful is insufficient. By using certain types of images, text, or combinations, a meme can become a multimodal type of hate speech.",
779
+ contact="pinjin",
780
+ version=_VERSION,
781
+ type_="classification_multiclass",
782
+ format_="coco",
783
+ root_folder="classification/hateful_memes_20211014",
784
+ train={
785
+ "index_path": "train_meta.json",
786
+ "files_for_local_usage": ["img.zip"],
787
+ "num_images": 8500
788
+ },
789
+ val=None,
790
+ test={
791
+ "index_path": "test_meta.json",
792
+ "files_for_local_usage": ["img.zip"],
793
+ "num_images": 500
794
+ },
795
+ labelmap="labels.txt",
796
+ num_classes=2,
797
+ citation=_HATEFUL_MEMES_CITATION,
798
+ url=_BASE_URL,
799
+ ),
800
  ]
801
 
802
  def _info(self):
803
+ if self.config.name == "voc-2007-classification":
804
+ features = datasets.Features(
805
+ {
806
+ "image_file_path": datasets.Value("string"),
807
+ "image": datasets.Image(),
808
+ "labels": [datasets.Value("int32")]
809
+ }
810
+ )
811
+ else:
812
+ features = datasets.Features(
813
+ {
814
+ "image_file_path": datasets.Value("string"),
815
+ "image": datasets.Image(),
816
+ "labels": datasets.Value("int32")
817
+ }
818
+ )
819
  return datasets.DatasetInfo(
820
  description=self.config.description,
821
  features=features,
 
824
 
825
  def _split_generators(self, dl_manager):
826
  _URL = self.config.url + self.config.root_folder
 
 
827
  urls_to_download = {
 
828
  "train": {
829
  "images": os.path.join(_URL, self.config.train['files_for_local_usage'][0]),
830
  "index": os.path.join(_URL, self.config.train['index_path']),
 
834
  "index": os.path.join(_URL, self.config.test['index_path']),
835
  }
836
  }
837
+ if self.config.val is not None:
838
+ urls_to_download['val'] = {
839
+ "images": os.path.join(_URL, self.config.val['files_for_local_usage'][0]),
840
+ "index": os.path.join(_URL, self.config.val['index_path']),
841
+ }
842
+
843
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
844
 
845
+ SplitGenerator_list = [
846
  datasets.SplitGenerator(
847
  name=datasets.Split.TRAIN,
848
  gen_kwargs={
 
858
  "index": downloaded_files["test"]["index"],
859
  "split": datasets.Split.TEST,
860
  },
861
+ )]
862
+
863
+ if self.config.val is not None:
864
+ SplitGenerator_list.append(datasets.SplitGenerator(
865
+ name=datasets.Split.VALIDATION,
866
+ gen_kwargs={
867
+ "images": downloaded_files["val"]["images"],
868
+ "index": downloaded_files["val"]["index"],
869
+ "split": datasets.Split.VALIDATION,
870
+ },
871
+ ))
872
+
873
+ return SplitGenerator_list
874
 
875
  def _generate_examples(self, images, index, split):
876
+
877
+ if self.config.name in ["kitti-distance", "resisc45_clip", "hateful-memes"]:
878
+ with open(index, encoding="utf-8") as f:
879
+ data = json.load(f)
880
+ for i in range(len(data['images'])):
881
+ label = data['annotations'][i]['category_id']
882
+ path = images + '/' + data['images'][i]['file_name'].split('@')[1]
883
+ yield i, {
884
+ "image_file_path": path,
885
+ "image": path,
886
+ "labels": label,
887
+ }
888
+
889
+ else:
890
+ with open(index, "r") as f:
891
+ lines = f.readlines()
892
+ for i, line in enumerate(lines):
893
+ line_split = line[:-1].split(" ")
894
+
895
+ if len(line_split) > 3:
896
+ image_path_temp = " ".join(line_split[:-1])
897
+ path = images + '/' + image_path_temp.split('@')[1] # image_path_temp[0]
898
+ else:
899
+ path = images + '/' + line_split[0].split('@')[1]
900
+
901
+ if self.config.type == "classification_multilabel":
902
+ label = [int(x) for x in line_split[-1].split(',')]
903
+ else:
904
+ try:
905
+ label = int(line_split[1])
906
+ except:
907
+ if self.config.name == "eurosat_clip" and split == 'test':
908
+ label = 9
909
+
910
+ yield i, {
911
+ "image_file_path": path,
912
+ "image": path,
913
+ "labels": label,
914
+ }