microsoft / torchgeo

TorchGeo: datasets, samplers, transforms, and pre-trained models for geospatial data
https://www.osgeo.org/projects/torchgeo/
MIT License
2.74k stars 342 forks source link

Incompatible image size with RandomGeoSampler #1778

Open hfangcat opened 11 months ago

hfangcat commented 11 months ago

Discussed in https://github.com/microsoft/torchgeo/discussions/1773

Originally posted by **hfangcat** December 14, 2023 The code example is here: ```python from torchgeo.datasets import stack_samples from torch.utils.data import DataLoader from torchgeo.samplers import RandomGeoSampler, RandomBatchGeoSampler from torchgeo.datasets import ChesapeakeCVPR root = '/scratch/local/cvpr_chesapeake_landcover/' dataset_train = ChesapeakeCVPR(root, splits=['md-train'], layers=['naip-new', 'lc', 'nlcd'], download=False) sampler_train = RandomGeoSampler(dataset_train, size=224, length=1) loader_train = DataLoader(dataset_train, sampler=sampler_train, collate_fn=stack_samples) for i, data in enumerate(loader_train): images = data["image"] targets = data["mask"] print(images.shape, targets.shape) break ``` Then it shows the shape of images and targets: ``` torch.Size([1, 4, 176, 176]) torch.Size([1, 2, 176, 176]) ``` which is not compatible with 224: what I specified in the code `sampler_train = RandomGeoSampler(dataset_train, size=224, length=1)`, can the community help me find out why it happens?
dmeaux commented 11 months ago

Since you're just looking at Maryland, have you tried using ChesapeakeMD since it inherits from Chesapeake, which inherits from RasterDataset? I would think that each state's own class would give you a consistent projected resolution.

hfangcat commented 11 months ago

Since you're just looking at Maryland, have you tried using ChesapeakeMD since it inherits from Chesapeake, which inherits from RasterDataset? I would think that each state's own class would give you a consistent projected resolution.

@dmeaux Thanks! Actually, I will use all datasets afterward for training, this is just an example to test the dataloader :D But I can try what you mentioned if it is really hard to fix

adamjstewart commented 11 months ago

Note that ChesapeakeMD and friends only have masks, not images. Only ChesapeakeCVPR has both images and masks.

calebrob6 commented 2 months ago

Note, this could be solved if we create the concept of TileDatasets (being discussed in https://github.com/microsoft/torchgeo/pull/1353).

adamjstewart commented 2 months ago

Or if we convert ChesapeakeCVPR to a RasterDataset.