alkzar90 commited on
Commit
3b7918a
1 Parent(s): 13a2b0f

Add text description

Browse files
Files changed (1) hide show
  1. CC6204-Hackaton-Cub-Dataset.py +13 -8
CC6204-Hackaton-Cub-Dataset.py CHANGED
@@ -98,19 +98,24 @@ class CubDataset(datasets.GeneratorBasedBuilder):
98
  def _split_generators(self, dl_manager):
99
  train_files = []
100
  train_idx = []
 
101
  test_files = []
102
  test_idx = []
103
 
104
  # Download images
105
- data_files = dl_manager.download_and_extract(_URLS["image_urls"])
106
- path_files = dl_manager.iter_files(data_files)
107
- for img in path_files:
 
 
 
 
108
  img_idx = _IMGNAME2ID[os.path.basename(img)]
109
  if img_idx in _TRAIN_IDX_SET:
110
- train_files.append(img)
111
  train_idx.append(img_idx)
112
  else:
113
- test_files.append(img)
114
  test_idx.append(img_idx)
115
 
116
  return [
@@ -134,11 +139,11 @@ class CubDataset(datasets.GeneratorBasedBuilder):
134
  def _generate_examples(self, files, image_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
- "description": "lala",
142
  "label": _ID2LABEL[_IMGID2CLASSID[image_idx[i]]],
143
  }
144
 
 
98
  def _split_generators(self, dl_manager):
99
  train_files = []
100
  train_idx = []
101
+
102
  test_files = []
103
  test_idx = []
104
 
105
  # Download images
106
+ img_data_files = dl_manager.download_and_extract(_URLS["image_urls"])
107
+ text_data_files = dl_manager.download_and_extract(_URLS["text_urls"])
108
+
109
+ img_path_files = dl_manager.iter_files(img_data_files)
110
+ text_path_files = dl_manager.iter_files(text_data_files)
111
+
112
+ for img, text in zip(img_path_files, text_path_files):
113
  img_idx = _IMGNAME2ID[os.path.basename(img)]
114
  if img_idx in _TRAIN_IDX_SET:
115
+ train_files.append((img, text))
116
  train_idx.append(img_idx)
117
  else:
118
+ test_files.append((img, text))
119
  test_idx.append(img_idx)
120
 
121
  return [
 
139
  def _generate_examples(self, files, image_idx):
140
 
141
  for i, path in enumerate(files):
142
+ file_name = os.path.basename(path[0])
143
  if file_name.endswith(".jpg"):
144
  yield i, {
145
+ "image": path[0],
146
+ "description": path[1],
147
  "label": _ID2LABEL[_IMGID2CLASSID[image_idx[i]]],
148
  }
149