system HF staff commited on
Commit
b18e7d4
1 Parent(s): 1b501b6

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. cifar10.py +12 -12
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  annotations_creators:
3
  - crowdsourced
4
  language_creators:
 
1
  ---
2
+ pretty_name: Cifar10
3
  annotations_creators:
4
  - crowdsourced
5
  language_creators:
cifar10.py CHANGED
@@ -17,7 +17,6 @@
17
  """CIFAR-10 Data Set"""
18
 
19
 
20
- import os
21
  import pickle
22
 
23
  import numpy as np
@@ -81,15 +80,18 @@ class Cifar10(datasets.GeneratorBasedBuilder):
81
  )
82
 
83
  def _split_generators(self, dl_manager):
84
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
85
- final_dir = os.path.join(dl_dir, "cifar-10-batches-py")
86
 
87
  return [
88
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": final_dir, "split": "train"}),
89
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": final_dir, "split": "test"}),
 
 
 
 
90
  ]
91
 
92
- def _generate_examples(self, filepath, split):
93
  """This function returns the examples in the raw (text) form."""
94
 
95
  if split == "train":
@@ -97,13 +99,11 @@ class Cifar10(datasets.GeneratorBasedBuilder):
97
 
98
  if split == "test":
99
  batches = ["test_batch"]
 
100
 
101
- for batch in batches:
102
-
103
- file = os.path.join(filepath, batch)
104
-
105
- with open(file, "rb") as fo:
106
 
 
107
  dict = pickle.load(fo, encoding="bytes")
108
 
109
  labels = dict[b"labels"]
@@ -113,7 +113,7 @@ class Cifar10(datasets.GeneratorBasedBuilder):
113
 
114
  img_reshaped = np.transpose(np.reshape(images[idx], (3, 32, 32)), (1, 2, 0))
115
 
116
- yield f"{batch}_{idx}", {
117
  "img": img_reshaped,
118
  "label": labels[idx],
119
  }
 
17
  """CIFAR-10 Data Set"""
18
 
19
 
 
20
  import pickle
21
 
22
  import numpy as np
 
80
  )
81
 
82
  def _split_generators(self, dl_manager):
83
+ archive = dl_manager.download(_DATA_URL)
 
84
 
85
  return [
86
+ datasets.SplitGenerator(
87
+ name=datasets.Split.TRAIN, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "train"}
88
+ ),
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.TEST, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "test"}
91
+ ),
92
  ]
93
 
94
+ def _generate_examples(self, files, split):
95
  """This function returns the examples in the raw (text) form."""
96
 
97
  if split == "train":
 
99
 
100
  if split == "test":
101
  batches = ["test_batch"]
102
+ batches = [f"cifar-10-batches-py/{filename}" for filename in batches]
103
 
104
+ for path, fo in files:
 
 
 
 
105
 
106
+ if path in batches:
107
  dict = pickle.load(fo, encoding="bytes")
108
 
109
  labels = dict[b"labels"]
 
113
 
114
  img_reshaped = np.transpose(np.reshape(images[idx], (3, 32, 32)), (1, 2, 0))
115
 
116
+ yield f"{path}_{idx}", {
117
  "img": img_reshaped,
118
  "label": labels[idx],
119
  }