Skip to content

Commit d8574a0

Browse files
ashnair1isaaccorley
authored andcommitted
Update VHR-10 snippet (#1920)
* Update VHR-10 snippet * Remove augs
1 parent cdaada0 commit d8574a0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,29 @@ TorchGeo includes a number of [*benchmark datasets*](https://torchgeo.readthedoc
119119
If you've used [torchvision](https://pytorch.org/vision) before, these datasets should seem very familiar. In this example, we'll create a dataset for the Northwestern Polytechnical University (NWPU) very-high-resolution ten-class ([VHR-10](https://github.com/chaozhong2010/VHR-10_dataset_coco)) geospatial object detection dataset. This dataset can be automatically downloaded, checksummed, and extracted, just like with torchvision.
120120

121121
```python
122+
from torch.utils.data import DataLoader
123+
124+
from torchgeo.datamodules.utils import collate_fn_detection
125+
from torchgeo.datasets import VHR10
126+
127+
# Initialize the dataset
122128
dataset = VHR10(root="...", download=True, checksum=True)
123-
dataloader = DataLoader(dataset, batch_size=128, shuffle=True, num_workers=4)
124129

130+
# Initialize the dataloader with the custom collate function
131+
dataloader = DataLoader(
132+
dataset,
133+
batch_size=128,
134+
shuffle=True,
135+
num_workers=4,
136+
collate_fn=collate_fn_detection,
137+
)
138+
139+
# Training loop
125140
for batch in dataloader:
126-
image = batch["image"]
127-
label = batch["label"]
141+
images = batch["image"] # list of images
142+
boxes = batch["boxes"] # list of boxes
143+
labels = batch["labels"] # list of labels
144+
masks = batch["masks"] # list of masks
128145

129146
# train a model, or make predictions using a pre-trained model
130147
```

0 commit comments

Comments
 (0)