Datasets:
Update README.md
Browse files
README.md
CHANGED
@@ -92,6 +92,42 @@ for batch in dataloader:
|
|
92 |
break
|
93 |
```
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
If you have any issues with data loading, please create a discussion in the community tab and tag `@blumenstiel`.
|
96 |
|
97 |
---
|
|
|
92 |
break
|
93 |
```
|
94 |
|
95 |
+
We provide some additional code for wrapping `albumentations` transform functions.
|
96 |
+
We recommend albumentations because parameters are shared between all image modalities (e.g., same random crop).
|
97 |
+
However, it requires some wrapping to bring the data into the expected shape.
|
98 |
+
```python
|
99 |
+
import albumentations as A
|
100 |
+
from albumentations.pytorch import ToTensorV2
|
101 |
+
from terramesh import build_terramesh_dataset, Transpose, MultimodalTransforms
|
102 |
+
|
103 |
+
# Define all image modalities
|
104 |
+
modalities = ["S2L2A", "S1GRD", "S1RTC", "DEM"]
|
105 |
+
|
106 |
+
# Define multimodal transform function that converts the data into the expected shape from albumentations
|
107 |
+
val_transform = MultimodalTransforms(
|
108 |
+
transforms=A.Compose([ # We use albumentations because of the shared transform between image modalities
|
109 |
+
Transpose([1, 2, 0]), # Convert data to channel last (expected shape from albumentations)
|
110 |
+
A.CenterCrop(224, 224), # Use center crop in val split
|
111 |
+
# A.RandomCrop(224, 224), # Use random crop in train split
|
112 |
+
# A.D4(), # Optionally, use random flipping and rotation for the train split
|
113 |
+
ToTensorV2(), # Convert to tensor and back to channel first
|
114 |
+
],
|
115 |
+
is_check_shapes=False, # Not needed because of aligned data in TerraMesh
|
116 |
+
additional_targets={m: "image" for m in modalities}
|
117 |
+
),
|
118 |
+
non_image_modalities=["__key__", "__url__"], # Additional non-image keys
|
119 |
+
)
|
120 |
+
|
121 |
+
dataset = build_terramesh_dataset(
|
122 |
+
path="https://huggingface.co/datasets/ibm-esa-geospatial/TerraMesh/resolve/main/", # Streaming or local path
|
123 |
+
modalities=modalities,
|
124 |
+
split='val',
|
125 |
+
transform=val_transform,
|
126 |
+
batch_size=8,
|
127 |
+
)
|
128 |
+
```
|
129 |
+
|
130 |
+
|
131 |
If you have any issues with data loading, please create a discussion in the community tab and tag `@blumenstiel`.
|
132 |
|
133 |
---
|