mathiaszinnen commited on
Commit
6ca1ef4
·
1 Parent(s): b5421ed

Fix filepointer bug

Browse files
Files changed (1) hide show
  1. odor.py +14 -13
odor.py CHANGED
@@ -74,7 +74,7 @@ class ODOR(datasets.GeneratorBasedBuilder):
74
  )
75
 
76
  def _split_generators(self, dl_manager):
77
- imgs_dir = f'{self.cache_dir}/images' # probably better to use the huggingface cache dir here
78
  csv_pth = 'meta/meta.csv'
79
  if not os.path.isdir(imgs_dir):
80
  os.makedirs(imgs_dir)
@@ -123,18 +123,19 @@ class ODOR(datasets.GeneratorBasedBuilder):
123
  for path in os.listdir(img_dir):
124
  file_name = os.path.basename(path)
125
  if file_name in image_id_to_image:
126
- image = image_id_to_image[file_name]
127
- objects = [
128
- process_annot(annot, category_id_to_category) for annot in image_id_to_annotations[image["id"]]
129
- ]
130
- yield idx, {
131
- "image_id": image["id"],
132
- "image": {"path": path, "bytes": f.read()},
133
- "width": image["width"],
134
- "height": image["height"],
135
- "objects": objects,
136
- }
137
- idx += 1
 
138
 
139
  if __name__ == '__main__':
140
  ds_builder = ODOR()
 
74
  )
75
 
76
  def _split_generators(self, dl_manager):
77
+ imgs_dir = f'{self.cache_dir}/images'
78
  csv_pth = 'meta/meta.csv'
79
  if not os.path.isdir(imgs_dir):
80
  os.makedirs(imgs_dir)
 
123
  for path in os.listdir(img_dir):
124
  file_name = os.path.basename(path)
125
  if file_name in image_id_to_image:
126
+ with open(f'{img_dir}/{path}','rb') as f:
127
+ image = image_id_to_image[file_name]
128
+ objects = [
129
+ process_annot(annot, category_id_to_category) for annot in image_id_to_annotations[image["id"]]
130
+ ]
131
+ yield idx, {
132
+ "image_id": image["id"],
133
+ "image": {"path": path, "bytes": f.read()},
134
+ "width": image["width"],
135
+ "height": image["height"],
136
+ "objects": objects,
137
+ }
138
+ idx += 1
139
 
140
  if __name__ == '__main__':
141
  ds_builder = ODOR()