alkzar90 commited on
Commit
3dede87
1 Parent(s): 5d2aa2d

Update CC6204-Hackaton-Cub-Dataset.py

Browse files
Files changed (1) hide show
  1. CC6204-Hackaton-Cub-Dataset.py +10 -4
CC6204-Hackaton-Cub-Dataset.py CHANGED
@@ -87,7 +87,9 @@ class CubDataset(datasets.GeneratorBasedBuilder):
87
 
88
  def _split_generators(self, dl_manager):
89
  train_files = []
 
90
  test_files = []
 
91
 
92
  # Download images
93
  data_files = dl_manager.download_and_extract(_URLS["mini_images_urls"])
@@ -96,8 +98,10 @@ class CubDataset(datasets.GeneratorBasedBuilder):
96
  img_idx = _IMGNAME2ID[os.path.basename(img)]
97
  if img_idx in _TRAIN_IDX_SET:
98
  train_files.append(img)
 
99
  else:
100
  test_files.append(img)
 
101
 
102
  #for batch in data_files:
103
  #path_files = dl_manager.iter_files(batch)
@@ -113,25 +117,27 @@ class CubDataset(datasets.GeneratorBasedBuilder):
113
  datasets.SplitGenerator(
114
  name=datasets.Split.TRAIN,
115
  gen_kwargs={
116
- "files": train_files
 
117
  }
118
  ),
119
  datasets.SplitGenerator(
120
  name=datasets.Split.TEST,
121
  gen_kwargs={
122
- "files": test_files
 
123
  }
124
  )
125
  ]
126
 
127
 
128
- def _generate_examples(self, files):
129
 
130
  for i, path in enumerate(files):
131
  file_name = os.path.basename(path)
132
  if file_name.endswith(".jpg"):
133
  yield i, {
134
  "image": path,
135
- "labels": _ID2LABEL[int(re.search("^\d+", file_name).group(0))],
136
  }
137
 
 
87
 
88
  def _split_generators(self, dl_manager):
89
  train_files = []
90
+ train_idx = []
91
  test_files = []
92
+ test_idx = []
93
 
94
  # Download images
95
  data_files = dl_manager.download_and_extract(_URLS["mini_images_urls"])
 
98
  img_idx = _IMGNAME2ID[os.path.basename(img)]
99
  if img_idx in _TRAIN_IDX_SET:
100
  train_files.append(img)
101
+ train_idx.append(img_idx)
102
  else:
103
  test_files.append(img)
104
+ test_idx.append(img_idx)
105
 
106
  #for batch in data_files:
107
  #path_files = dl_manager.iter_files(batch)
 
117
  datasets.SplitGenerator(
118
  name=datasets.Split.TRAIN,
119
  gen_kwargs={
120
+ "files": train_files,
121
+ "image_idx": train_idx
122
  }
123
  ),
124
  datasets.SplitGenerator(
125
  name=datasets.Split.TEST,
126
  gen_kwargs={
127
+ "files": test_files,
128
+ "image_idx": test_idx
129
  }
130
  )
131
  ]
132
 
133
 
134
+ def _generate_examples(self, files, idx):
135
 
136
  for i, path in enumerate(files):
137
  file_name = os.path.basename(path)
138
  if file_name.endswith(".jpg"):
139
  yield i, {
140
  "image": path,
141
+ "labels": _ID2LABEL[idx[i]],
142
  }
143