Tylersuard commited on
Commit
383bb88
·
1 Parent(s): cdbfb65

Update PathfinderX2.py

Browse files
Files changed (1) hide show
  1. PathfinderX2.py +21 -18
PathfinderX2.py CHANGED
@@ -89,7 +89,7 @@ class PathfinderX2(datasets.GeneratorBasedBuilder):
89
  ),
90
  ]
91
 
92
- def _generate_examples(self, data, split):
93
  if split == "training":
94
  images_dir, annotations_dir = data
95
  image_dict = {}
@@ -102,20 +102,23 @@ class PathfinderX2(datasets.GeneratorBasedBuilder):
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
- }
 
 
 
 
89
  ),
90
  ]
91
 
92
+ def _generate_examples(self, data, split):
93
  if split == "training":
94
  images_dir, annotations_dir = data
95
  image_dict = {}
 
102
  image_id = os.path.splitext(file_annot)[0]
103
  annotation_dict[image_id] = os.path.join(root, file_annot)
104
 
105
+ idx = 0
106
+ for root, _, files in os.walk(images_dir):
107
+ for file_img in files:
108
+ if file_img.endswith(".png"):
109
+ image_id = os.path.splitext(file_img)[0]
110
+ image_dict[image_id] = os.path.join(root, file_img)
111
+
112
+ path_img = image_dict[image_id]
113
+ path_annot = annotation_dict[image_id]
114
+
115
+ with open(path_img, "rb") as f_img:
116
+ bytes_img = f_img.read()
117
+ with open(path_annot, "rb") as f_annot:
118
+ bytes_annot = f_annot.read()
119
+
120
+ yield idx, {
121
+ "image": {"path": path_img, "bytes": bytes_img},
122
+ "annotation": {"path": path_annot, "bytes": bytes_annot},
123
+ }
124
+ idx += 1