Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible image size with RandomGeoSampler #1778

Open
hfangcat opened this issue Dec 15, 2023 Discussed in #1773 · 5 comments
Open

Incompatible image size with RandomGeoSampler #1778

hfangcat opened this issue Dec 15, 2023 Discussed in #1773 · 5 comments
Assignees
Labels
datasets Geospatial or benchmark datasets

Comments

@hfangcat
Copy link

Discussed in #1773

Originally posted by hfangcat December 14, 2023
The code example is here:

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?

@adamjstewart adamjstewart added the datasets Geospatial or benchmark datasets label Dec 15, 2023
@dmeaux
Copy link
Contributor

dmeaux commented Dec 15, 2023

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
Copy link
Author

hfangcat commented Dec 15, 2023

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
Copy link
Collaborator

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

@calebrob6
Copy link
Member

Note, this could be solved if we create the concept of TileDatasets (being discussed in #1353).

@adamjstewart
Copy link
Collaborator

Or if we convert ChesapeakeCVPR to a RasterDataset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets
Projects
None yet
Development

No branches or pull requests

4 participants