Closed jaywonchung closed 4 years ago
I temporarily resolved this issue by writing my own mapper. The following snipper will be enough:
# Apply self.tfm_gens to image. Build transform list for sem_seg_gt.
transforms_gt = []
for g in self.tfm_gens:
tfm = g.get_transform(image)
if isinstance(g, T.ResizeShortestEdge):
if self.is_train:
min_size = self.cfg.INPUT.MIN_SIZE_TRAIN
max_size = self.cfg.INPUT.MAX_SIZE_TRAIN
sample_style = self.cfg.INPUT.MIN_SIZE_TRAIN_SAMPLING
else:
min_size = self.cfg.INPUT.MIN_SIZE_TEST
max_size = self.cfg.INPUT.MAX_SIZE_TEST
sample_style = "choice"
tfm_gt = T.ResizeShortestEdge(
short_edge_length=min_size,
max_size=max_size,
sample_style=sample_style,
interp=Image.NEAREST
).get_transform(image)
transforms_gt.append(tfm_gt)
else:
transforms_gt.append(tfm)
image = tfm.apply_image(image)
Although this issue can be circumvented, improving the default behavior (of DatasetMapper) for semantic segmentation will be great.
. By default T.ResizeShortestEdge resizes images with bilinear interpolation,
I don't think that will happen to segmentation: https://github.com/facebookresearch/detectron2/blob/3e994e353b0513c8994c3964b4585191f04ea14f/detectron2/data/transforms/transform.py#L92-L94
Let us know if that contradicts with what you observed.
Description
The following snippet is from the last part of
detectron2.data.DatasetMapper
.It can be seen that
transforms
is directly applied to the semantic segmentation ground truth array atHowever, I encounterd a problem due to the
T.ResizeShortestEdge
transform included intransforms
. By defaultT.ResizeShortestEdge
resizes images with bilinear interpolation, and this broke my integer labels in the semantic segmentaion ground truth arrays.Environment: