Skip to content

Commit 337f7a0

Browse files
zhiltsov-maxnmanovic
authored andcommitted
[Datumaro] Fix project loading (#1013)
* Fix occasional infinite loop in project loading * Fix project import source options saving * Fix project import .git dir placement * Make code aware of grayscale images
1 parent 4d730c7 commit 337f7a0

File tree

14 files changed

+35
-19
lines changed

14 files changed

+35
-19
lines changed

datumaro/datumaro/components/algorithms/rise.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def normalize_hmaps(self, heatmaps, counts):
8080
def apply(self, image, progressive=False):
8181
import cv2
8282

83-
assert len(image.shape) == 3, \
83+
assert len(image.shape) in [2, 3], \
8484
"Expected an input image in (H, W, C) format"
85-
assert image.shape[2] in [3, 4], \
86-
"Expected BGR or BGRA input"
85+
if len(image.shape) == 3:
86+
assert image.shape[2] in [3, 4], "Expected BGR or BGRA input"
8787
image = image[:, :, :3].astype(np.float32)
8888

8989
model = self.model

datumaro/datumaro/components/converters/ms_coco.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def is_empty(self):
6262

6363
def save_image_info(self, item, filename):
6464
if item.has_image:
65-
h, w, _ = item.image.shape
65+
h, w = item.image.shape[:2]
6666
else:
6767
h = 0
6868
w = 0
@@ -187,7 +187,7 @@ def save_annotations(self, item):
187187
p.label == ann.label]
188188
if polygons:
189189
segmentation = [p.get_points() for p in polygons]
190-
h, w, _ = item.image.shape
190+
h, w = item.image.shape[:2]
191191
rles = mask_utils.frPyObjects(segmentation, h, w)
192192
rle = mask_utils.merge(rles)
193193
area = mask_utils.area(rle)
@@ -211,7 +211,7 @@ def save_annotations(self, item):
211211
area = ann.area()
212212

213213
if self._context._merge_polygons:
214-
h, w, _ = item.image.shape
214+
h, w = item.image.shape[:2]
215215
rles = mask_utils.frPyObjects(segmentation, h, w)
216216
rle = mask_utils.merge(rles)
217217
area = mask_utils.area(rle)

datumaro/datumaro/components/converters/tfrecord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def float_list_feature(value):
4848
if not item.has_image:
4949
raise Exception(
5050
"Failed to export dataset item '%s': item has no image" % item.id)
51-
height, width, _ = item.image.shape
51+
height, width = item.image.shape[:2]
5252

5353
features.update({
5454
'image/height': int64_feature(height),

datumaro/datumaro/components/converters/voc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def save_subsets(self):
153153
ET.SubElement(source_elem, 'image').text = 'Unknown'
154154

155155
if item.has_image:
156-
h, w, c = item.image.shape
156+
image_shape = item.image.shape
157+
h, w = image_shape[:2]
158+
c = 1 if len(image_shape) == 2 else image_shape[2]
157159
size_elem = ET.SubElement(root_elem, 'size')
158160
ET.SubElement(size_elem, 'width').text = str(w)
159161
ET.SubElement(size_elem, 'height').text = str(h)

datumaro/datumaro/components/converters/yolo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __call__(self, extractor, save_dir):
9292
if not osp.exists(image_path):
9393
save_image(image_path, item.image)
9494

95-
height, width, _ = item.image.shape
95+
height, width = item.image.shape[:2]
9696

9797
yolo_annotation = ''
9898
for bbox in item.annotations:

datumaro/datumaro/components/dataset_filter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def encode_item(self, item):
4343
def encode_image(cls, image):
4444
image_elem = ET.Element('image')
4545

46-
h, w, c = image.shape
46+
h, w = image.shape[:2]
47+
c = 1 if len(image.shape) == 2 else image.shape[2]
4748
ET.SubElement(image_elem, 'width').text = str(w)
4849
ET.SubElement(image_elem, 'height').text = str(h)
4950
ET.SubElement(image_elem, 'depth').text = str(c)

datumaro/datumaro/components/importers/cvat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __call__(self, path, **extra_params):
4040
project.add_source(subset_name, {
4141
'url': subset_path,
4242
'format': self.EXTRACTOR_NAME,
43-
'options': extra_params,
43+
'options': dict(extra_params),
4444
})
4545

4646
return project

datumaro/datumaro/components/importers/datumaro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __call__(self, path, **extra_params):
4040
project.add_source(subset_name, {
4141
'url': subset_path,
4242
'format': self.EXTRACTOR_NAME,
43-
'options': extra_params,
43+
'options': dict(extra_params),
4444
})
4545

4646
return project

datumaro/datumaro/components/importers/ms_coco.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __call__(self, path, **extra_params):
3737
project.add_source(source_name, {
3838
'url': ann_file,
3939
'format': self._COCO_EXTRACTORS[ann_type],
40-
'options': extra_params,
40+
'options': dict(extra_params),
4141
})
4242

4343
return project

datumaro/datumaro/components/importers/tfrecord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __call__(self, path, **extra_params):
3535
project.add_source(subset_name, {
3636
'url': subset_path,
3737
'format': self.EXTRACTOR_NAME,
38-
'options': extra_params,
38+
'options': dict(extra_params),
3939
})
4040

4141
return project

0 commit comments

Comments
 (0)