siavava commited on
Commit
bdf60da
1 Parent(s): 7342de5

Update mmod2.py

Browse files
Files changed (1) hide show
  1. mmod2.py +11 -10
mmod2.py CHANGED
@@ -5,6 +5,8 @@ from os.path import (
5
  basename
6
  # listdir
7
  )
 
 
8
  import random
9
  import scipy.io
10
  import datasets
@@ -98,16 +100,15 @@ class Mmod2(datasets.GeneratorBasedBuilder):
98
  # if file_basename in files_to_keep:
99
 
100
  raw_image_file = f"{self.data_dir}/data/{_IMAGES_DIR}/{file_name}.jpg"
101
- annotation = scipy.io.loadmat(f"{self.data_dir}/data/{_ANNOTATIONS_DIR}/{file_name}.mat")["annotations"][0][0][0]
102
- # print(f"{annotation = }")
103
-
104
- image = Image.open(raw_image_file)
105
-
106
-
107
- yield file_name, {
108
- "image": image, # {"path": file_path, "bytes": file_obj.read()},
109
- "label": self.decode_labels(image, annotation),
110
- }
111
 
112
  def decode_labels(self, image: Image.Image, mask, num_images=1, num_classes=3):
113
  """Decode batch of segmentation masks.
 
5
  basename
6
  # listdir
7
  )
8
+ import os.path
9
+
10
  import random
11
  import scipy.io
12
  import datasets
 
100
  # if file_basename in files_to_keep:
101
 
102
  raw_image_file = f"{self.data_dir}/data/{_IMAGES_DIR}/{file_name}.jpg"
103
+
104
+ if os.path.exists(raw_image_image) and os.path.exists(annotation_file):
105
+ image = Image.open(raw_image_file)
106
+ annotation = scipy.io.loadmat(f"{self.data_dir}/data/{_ANNOTATIONS_DIR}/{file_name}.mat")["annotations"][0][0][0]
107
+
108
+ yield file_name, {
109
+ "image": image, # {"path": file_path, "bytes": file_obj.read()},
110
+ "label": self.decode_labels(image, annotation),
111
+ }
 
112
 
113
  def decode_labels(self, image: Image.Image, mask, num_images=1, num_classes=3):
114
  """Decode batch of segmentation masks.