Skip to content

Commit 9e383e2

Browse files
committed
voc metadata corrected
1 parent f04c9f4 commit 9e383e2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

superannotate/input_converters/converters/voc_converters/voc_helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ def _iou(bbox1, bbox2):
3939
(xmax1 - xmin1) * (ymax1 - ymin1) + (xmax2 - xmin2) *
4040
(ymax2 - ymin2) - x * y
4141
)
42+
43+
44+
def _get_image_shape_from_xml(file_path):
45+
with open(os.path.splitext(file_path)[0] + ".xml") as f:
46+
tree = ET.parse(f)
47+
48+
size = tree.find('size')
49+
width = int(size.find('width').text)
50+
height = int(size.find('height').text)
51+
52+
return height, width

superannotate/input_converters/converters/voc_converters/voc_to_sa_pixel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from ....common import blue_color_generator, hex_to_rgb, write_to_json
55
from ..sa_json_helper import _create_pixel_instance, _create_sa_json
6-
from .voc_helper import _get_voc_instances_from_xml, _iou
6+
from .voc_helper import _get_voc_instances_from_xml, _iou, _get_image_shape_from_xml
77

88

99
def _generate_polygons(object_mask_path):
@@ -61,7 +61,7 @@ def _generate_instances(polygon_instances, voc_instances, bluemask_colors):
6161
attributes = voc_instances[ind][0][class_name]
6262
instances.append(
6363
{
64-
"className": voc_instances[ind][0],
64+
"className": class_name,
6565
"polygon": polygon,
6666
"bbox": voc_instances[ind][1],
6767
"blue_color": bluemask_colors[i],
@@ -100,7 +100,10 @@ def voc_instance_segmentation_to_sa_pixel(voc_root, output_dir):
100100
sa_instances.append(sa_obj)
101101

102102
file_name = "%s.jpg___pixel.json" % (filename.stem)
103-
sa_metadata = {'name': filename.stem}
103+
height, width = _get_image_shape_from_xml(
104+
annotation_dir / filename.name
105+
)
106+
sa_metadata = {'name': filename.stem, 'height': height, 'width': width}
104107
sa_json = _create_sa_json(sa_instances, sa_metadata)
105108
write_to_json(output_dir / file_name, sa_json)
106109

superannotate/input_converters/converters/voc_converters/voc_to_sa_vector.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ....common import write_to_json
66
from ..sa_json_helper import _create_sa_json, _create_vector_instance
7-
from .voc_helper import _get_voc_instances_from_xml, _iou
7+
from .voc_helper import _get_voc_instances_from_xml, _iou, _get_image_shape_from_xml
88

99

1010
def _generate_polygons(object_mask_path):
@@ -99,7 +99,10 @@ def voc_instance_segmentation_to_sa_vector(voc_root, output_dir):
9999
sa_instances.append(sa_obj)
100100

101101
file_name = "%s.jpg___objects.json" % filename.stem
102-
sa_metadata = {'name': filename.stem}
102+
height, width = _get_image_shape_from_xml(
103+
annotation_dir / filename.name
104+
)
105+
sa_metadata = {'name': filename.stem, 'height': height, 'width': width}
103106
sa_json = _create_sa_json(sa_instances, sa_metadata)
104107
write_to_json(output_dir / file_name, sa_json)
105108
return classes
@@ -125,7 +128,10 @@ def voc_object_detection_to_sa_vector(voc_root, output_dir):
125128
sa_instances.append(sa_obj)
126129

127130
file_name = "%s.jpg___objects.json" % filename.stem
128-
sa_metadata = {'name': filename.stem}
131+
height, width = _get_image_shape_from_xml(
132+
annotation_dir / filename.name
133+
)
134+
sa_metadata = {'name': filename.stem, 'height': height, 'width': width}
129135
sa_json = _create_sa_json(sa_instances, sa_metadata)
130136
write_to_json(output_dir / file_name, sa_json)
131137
return classes

0 commit comments

Comments
 (0)