Update mmod2.py
Browse files
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 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
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.
|