torchgeo icon indicating copy to clipboard operation
torchgeo copied to clipboard

OSCDDataModule not compatible with SemanticSegmentationTask

Open adamjstewart opened this issue 3 years ago • 0 comments

OSCD is a change detection dataset. OSCDDataset.__getitem__ returns an "image" of shape [2 x C x H x W]. Most of our other datasets return images of shape [C x H x W], and SemanticSegmentationTask is designed to work with these kind of images. It looks like there are some hacks in OSCDDataModule to work around this, but these hacks are very unreliable. For example, in:

mask = repeat(sample["mask"], "h w -> t h w", t=2).float()               
image, mask = self.rcrop(sample["image"], mask)                          
mask = mask.squeeze()[0]                                                 
images.append(image.squeeze())                                           
masks.append(mask.long())         

we use squeeze() without specifying which dimension to remove. This has different behavior when batch size is 1 vs >1, so we should avoid using this.

To fix this, I think we could either change __getitem__ to return an "image" of shape [2C x H x W] or create a new ChangeDetectionTask for these kinds of datasets.

See the following comments for additional discussion/issues:

  • https://github.com/microsoft/torchgeo/pull/329#pullrequestreview-840627512
  • https://github.com/microsoft/torchgeo/pull/329#issuecomment-1003144109

adamjstewart avatar Dec 30 '21 19:12 adamjstewart