torchgeo icon indicating copy to clipboard operation
torchgeo copied to clipboard

Cheasapeake test set image and label size are 2x bigger

Open recursix opened this issue 2 years ago • 2 comments

Description

the dataloader from the test set of Cheasapeak returns images 2x bigger.

Most likely due to test_transforms from the setup function which has a different configuration than e.g. the validation set. It uses pad_to(self.original_patch_size... instead of center_crop(self.patch_size)

Steps to reproduce


   def convert_test():
    states = ["de", "md", "va", "wv", "pa", "ny"]

    dm = ChesapeakeCVPRDataModule(
        root_dir=SRC_DATASET_DIR,
        train_splits=[f"{state}-train" for state in states],
        val_splits=[f"{state}-val" for state in states],
        test_splits=[f"{state}-test" for state in states],
        patches_per_tile=500,
        patch_size=256,
        batch_size=1,
        num_workers=0,
        class_set=7,
    )
    dm.prepare_data()
    dm.setup()

    test_dl = dm.test_dataloader()

    for sample in test_dl:
        image = np.array(sample["image"])[0]
        print(image.shape)  # this value is 512,512 and should be 256,256

Version

0.2.0

recursix avatar Jun 22 '22 01:06 recursix

@calebrob6 can you look into this?

adamjstewart avatar Jul 02 '22 00:07 adamjstewart

Yep, this is what happens, although I made this happen on purpose. The images from the test_dataloader look like this:

image

where the size of the nodata padded area varies. I did this because I wanted the test set metrics to be evaluated over all pixels in the test set (which wouldn't happen with the center cropping).

The reason this is even an issue in the first place is because of #409. In short:

  • By design a dataset must have a single CRS specified although the tiles that make up the dataset can be in different CRSs. For example, I say the ChesapeakeCVPR dataset is EPSG:3857, however all of the tiles themselves are in different UTM CRSs.
  • When you sample from a dataset the sampler will generate BoundingBox that are in terms of the dataset CRS. We will warp and resample the appropriate data from the underlying tiles to be pixel aligned in terms of the dataset CRS / resolution.
  • For datasets like ChesapeakeCVPR this doesn't make sense as everything is already pixel-aligned. We don't have a good way to deal with this.
    • As a hack, in the ChesapeakeCVPR case I instead reproject the BoundingBoxes which is cheaper than reprojecting the data. This causes the data returned by ChesapeakeCVPR to be different number of pixels, even though the BoundingBoxes generated by the sampler are the same size.

calebrob6 avatar Jul 02 '22 03:07 calebrob6

Is this fixed by #992? With this PR, we load all images to be 2x patch_size, then we center crop to patch_size for all train/val/test splits.

adamjstewart avatar Jan 22 '23 17:01 adamjstewart