@@ -103,17 +103,41 @@ def match_bboxes(raster_source: 'RasterSource',
103
103
label_source (LabelSource | LabelStore): Source of labels for a
104
104
scene. Can be a ``LabelStore``.
105
105
"""
106
+ from rastervision .core .data import (RasterioCRSTransformer ,
107
+ SemanticSegmentationLabelSource )
106
108
crs_tf_img = raster_source .crs_transformer
107
109
crs_tf_label = label_source .crs_transformer
108
110
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 ,
116
+ SemanticSegmentationLabelSource ) and isinstance (
117
+ crs_tf_label , RasterioCRSTransformer ):
118
+ if crs_tf_label .image_crs is None :
119
+ if raster_source .extent != label_source .extent :
120
+ raise ValueError (
121
+ f'Label source ({ label_source } ) is not georeferenced and '
122
+ f'has a different extent ({ label_source .extent } ) than the '
123
+ f"corresponding raster source's ({ raster_source } ) extent "
124
+ f'({ raster_source .extent } ).' )
125
+ log .warning (
126
+ f'Label source ({ label_source } ) is not georeferenced but has '
127
+ f'the same extent ({ label_source .extent } ) as the '
128
+ f'corresponding raster source ({ raster_source } ). '
129
+ 'Will assume they are aligned.' )
130
+ return
131
+
109
132
if label_source .bbox is not None :
110
133
bbox_label_map = crs_tf_label .pixel_to_map (label_source .bbox )
111
134
if not bbox_img_map .intersects (bbox_label_map ):
112
135
rs_cls = type (raster_source ).__name__
113
136
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
+
117
141
# set LabelStore bbox to RasterSource bbox
118
142
bbox_label_pixel = crs_tf_label .map_to_pixel (bbox_img_map )
119
143
label_source .set_bbox (bbox_label_pixel )
0 commit comments