Skip to content

Commit 79ce415

Browse files
committed
allow label GeoTIFFs to be un-georeferenced to unbreak potsdam example
1 parent 5ac4e6c commit 79ce415

File tree

1 file changed

+27
-3
lines changed
  • rastervision_core/rastervision/core/data/utils

1 file changed

+27
-3
lines changed

rastervision_core/rastervision/core/data/utils/misc.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,41 @@ def match_bboxes(raster_source: 'RasterSource',
103103
label_source (LabelSource | LabelStore): Source of labels for a
104104
scene. Can be a ``LabelStore``.
105105
"""
106+
from rastervision.core.data import (RasterioCRSTransformer,
107+
SemanticSegmentationLabelSource)
106108
crs_tf_img = raster_source.crs_transformer
107109
crs_tf_label = label_source.crs_transformer
108110
bbox_img_map = crs_tf_img.pixel_to_map(raster_source.bbox)
111+
112+
# For SS, if a label file is not georeferenced but is the same size as
113+
# the corresponding raster source (as is the case in the Potsdam dataset),
114+
# implicitly assume that they are aligned.
115+
if isinstance(label_source, SemanticSegmentationLabelSource):
116+
if crs_tf_label.image_crs is None:
117+
if raster_source.extent != label_source.extent:
118+
raise ValueError(
119+
f"Label source ({label_source.raster_source.uris}) is not "
120+
"georeferenced and has a different extent "
121+
f"({label_source.extent}) than the corresponding raster "
122+
f"source's ({raster_source.uris}) extent "
123+
f"({raster_source.extent})")
124+
log.warning(
125+
f"Label source ({label_source.raster_source.uris}) is not "
126+
"georeferenced but has the same extent "
127+
f"({label_source.extent}) as the corresponding raster "
128+
f"source ({raster_source.uris}). Will assume they are aligned."
129+
)
130+
return
131+
109132
if label_source.bbox is not None:
110133
bbox_label_map = crs_tf_label.pixel_to_map(label_source.bbox)
111134
if not bbox_img_map.intersects(bbox_label_map):
112135
rs_cls = type(raster_source).__name__
113136
ls_cls = type(label_source).__name__
114-
log.warning(f'{rs_cls} bbox ({bbox_img_map}) does '
115-
f'not intersect with {ls_cls} bbox '
116-
f'({bbox_label_map}).')
137+
raise ValueError(f'{rs_cls} bbox ({bbox_img_map}) does '
138+
f'not intersect with {ls_cls} bbox '
139+
f'({bbox_label_map}).')
140+
117141
# set LabelStore bbox to RasterSource bbox
118142
bbox_label_pixel = crs_tf_label.map_to_pixel(bbox_img_map)
119143
label_source.set_bbox(bbox_label_pixel)

0 commit comments

Comments
 (0)