Tylersuard commited on
Commit
cdbfb65
·
1 Parent(s): 76318e3

Update PathfinderX2.py

Browse files
Files changed (1) hide show
  1. PathfinderX2.py +27 -14
PathfinderX2.py CHANGED
@@ -74,10 +74,11 @@ class PathfinderX2(datasets.GeneratorBasedBuilder):
74
 
75
  def _split_generators(self, dl_manager):
76
  urls = _URLS[self.config.name]
77
- data_dirs = dl_manager.download(urls)
78
- train_data = dl_manager.iter_archive(data_dirs["images"]), dl_manager.iter_archive(
79
  data_dirs["annotations"]
80
  )
 
81
  return [
82
  datasets.SplitGenerator(
83
  name=datasets.Split.TRAIN,
@@ -90,19 +91,31 @@ class PathfinderX2(datasets.GeneratorBasedBuilder):
90
 
91
  def _generate_examples(self, data, split):
92
  if split == "training":
93
- images, annotations = data
94
  image_dict = {}
95
  annotation_dict = {}
 
96
  # loads the annotations for the split into RAM (less than 100 MB) to support streaming
97
- for path_annot, file_annot in annotations:
98
- if path_annot.endswith(".png"):
99
- image_id = os.path.basename(path_annot).split(".")[0]
100
- annotation_dict[image_id] = (path_annot, file_annot.read())
101
- for idx, (path_img, file_img) in enumerate(images):
102
- if path_img.endswith(".png"):
103
- image_id = os.path.basename(path_img).split(".")[0]
104
- path_annot, bytes_annot = image_dict[image_id]
 
 
 
 
 
 
 
 
 
 
 
105
  yield idx, {
106
- "image": {"path": path_img, "bytes": file_img.read()},
107
- "annotation": {"path": path_annot, "bytes": file_annot.read()}
108
- }
 
74
 
75
  def _split_generators(self, dl_manager):
76
  urls = _URLS[self.config.name]
77
+ data_dirs = dl_manager.download_and_extract(urls) # change from download to download_and_extract
78
+ train_data = os.path.join(data_dirs["images"]), os.path.join(
79
  data_dirs["annotations"]
80
  )
81
+
82
  return [
83
  datasets.SplitGenerator(
84
  name=datasets.Split.TRAIN,
 
91
 
92
  def _generate_examples(self, data, split):
93
  if split == "training":
94
+ images_dir, annotations_dir = data
95
  image_dict = {}
96
  annotation_dict = {}
97
+
98
  # loads the annotations for the split into RAM (less than 100 MB) to support streaming
99
+ for root, _, files in os.walk(annotations_dir):
100
+ for file_annot in files:
101
+ if file_annot.endswith(".png"):
102
+ image_id = os.path.splitext(file_annot)[0]
103
+ annotation_dict[image_id] = os.path.join(root, file_annot)
104
+
105
+ for idx, file_img in enumerate(os.listdir(images_dir)):
106
+ if file_img.endswith(".png"):
107
+ image_id = os.path.splitext(file_img)[0]
108
+ image_dict[image_id] = os.path.join(images_dir, file_img)
109
+
110
+ path_img = image_dict[image_id]
111
+ path_annot = annotation_dict[image_id]
112
+
113
+ with open(path_img, "rb") as f_img:
114
+ bytes_img = f_img.read()
115
+ with open(path_annot, "rb") as f_annot:
116
+ bytes_annot = f_annot.read()
117
+
118
  yield idx, {
119
+ "image": {"path": path_img, "bytes": bytes_img},
120
+ "annotation": {"path": path_annot, "bytes": bytes_annot},
121
+ }