Skip to content

Commit

Permalink
Merge branch 'main' into added_tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
cordmaur authored Dec 3, 2024
2 parents dfa3a6a + 5eeef2d commit fa4b8f8
Show file tree
Hide file tree
Showing 76 changed files with 1,118 additions and 12 deletions.
10 changes: 10 additions & 0 deletions docs/api/datamodules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ GID-15

.. autoclass:: GID15DataModule

HySpecNet-11k
^^^^^^^^^^^^^

.. autoclass:: HySpecNet11kDataModule

Inria Aerial Image Labeling
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -213,6 +218,11 @@ SustainBench Crop Yield

.. autoclass:: SustainBenchCropYieldDataModule

TreeSatAI
^^^^^^^^^

.. autoclass:: TreeSatAIDataModule

Tropical Cyclone
^^^^^^^^^^^^^^^^

Expand Down
10 changes: 10 additions & 0 deletions docs/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ GID-15

.. autoclass:: GID15

HySpecNet-11k
^^^^^^^^^^^^^

.. autoclass:: HySpecNet11k

IDTReeS
^^^^^^^

Expand Down Expand Up @@ -469,6 +474,11 @@ SustainBench Crop Yield

.. autoclass:: SustainBenchCropYield

TreeSatAI
^^^^^^^^^

.. autoclass:: TreeSatAI

Tropical Cyclone
^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions docs/api/datasets/non_geo_datasets.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Dataset,Task,Source,License,# Samples,# Classes,Size (px),Resolution (m),Bands
`Forest Damage`_,OD,Drone imagery,"CDLA-Permissive-1.0","1,543",4,"1,500x1,500",,RGB
`GeoNRW`_,S,Aerial,"CC-BY-4.0","7,783",11,"1,000x1,000",1,"RGB, DEM"
`GID-15`_,S,Gaofen-2,-,150,15,"6,800x7,200",3,RGB
`HySpecNet-11k`_,-,EnMAP,CC0-1.0,11k,-,128,30,HSI
`IDTReeS`_,"OD,C",Aerial,"CC-BY-4.0",591,33,200x200,0.1--1,RGB
`Inria Aerial Image Labeling`_,S,Aerial,-,360,2,"5,000x5,000",0.3,RGB
`LandCover.ai`_,S,Aerial,"CC-BY-NC-SA-4.0","10,674",5,512x512,0.25--0.5,RGB
Expand Down Expand Up @@ -52,6 +53,7 @@ Dataset,Task,Source,License,# Samples,# Classes,Size (px),Resolution (m),Bands
`SSL4EO-L Benchmark`_,S,Lansat & CDL,"CC0-1.0",25K,134,264x264,30,MSI
`SSL4EO-L Benchmark`_,S,Lansat & NLCD,"CC0-1.0",25K,17,264x264,30,MSI
`SustainBench Crop Yield`_,R,MODIS,"CC-BY-SA-4.0",11k,-,32x32,-,MSI
`TreeSatAI`_,"C, R, S","Aerial, Sentinel-1/2",CC-BY-4.0,50K,"12, 15, 20","6, 20, 304","0.2, 10","CIR, MSI, SAR"
`Tropical Cyclone`_,R,GOES 8--16,"CC-BY-4.0","108,110",-,256x256,4K--8K,MSI
`UC Merced`_,C,USGS National Map,"public domain","2,100",21,256x256,0.3,RGB
`USAVars`_,R,NAIP Aerial,"CC-BY-4.0",100K,-,-,4,"RGB, NIR"
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ dependencies = [
# pyproj 3.3+ required for Python 3.10 wheels
"pyproj>=3.3",
# rasterio 1.3+ required for Python 3.10 wheels
# rasterio 1.4+ no longer supports merging WarpedVRT objects
# rasterio 1.4.0-1.4.2 lack support for merging WarpedVRT objects
# https://github.com/rasterio/rasterio/issues/3196
"rasterio>=1.3,<1.4",
"rasterio>=1.3,!=1.4.0,!=1.4.1,!=1.4.2",
# rtree 1+ required for Python 3.10 wheels
"rtree>=1",
# segmentation-models-pytorch 0.2+ required for smp.losses module
Expand Down
6 changes: 3 additions & 3 deletions requirements/required.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ setuptools==75.6.0
einops==0.8.0
fiona==1.10.1
kornia==0.7.4
lightly==1.5.14
lightly==1.5.15
lightning[pytorch-extra]==2.4.0
matplotlib==3.9.2
matplotlib==3.9.3
numpy==2.1.3
pandas==2.2.3
pillow==11.0.0
pyproj==3.7.0
rasterio==1.3.11
rasterio==1.4.3
rtree==1.3.0
segmentation-models-pytorch==0.3.4
shapely==2.0.6
Expand Down
2 changes: 1 addition & 1 deletion requirements/style.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# style
mypy==1.13.0
ruff==0.8.0
ruff==0.8.1
2 changes: 1 addition & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tests
nbmake==1.5.4
pytest==8.3.3
pytest==8.3.4
pytest-cov==6.0.0
11 changes: 11 additions & 0 deletions tests/conf/hyspecnet_byol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
model:
class_path: BYOLTask
init_args:
model: 'resnet18'
in_channels: 202
data:
class_path: HySpecNet11kDataModule
init_args:
batch_size: 2
dict_kwargs:
root: 'tests/data/hyspecnet'
11 changes: 11 additions & 0 deletions tests/conf/hyspecnet_moco.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
model:
class_path: MoCoTask
init_args:
model: 'resnet18'
in_channels: 202
data:
class_path: HySpecNet11kDataModule
init_args:
batch_size: 2
dict_kwargs:
root: 'tests/data/hyspecnet'
11 changes: 11 additions & 0 deletions tests/conf/hyspecnet_simclr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
model:
class_path: SimCLRTask
init_args:
model: 'resnet18'
in_channels: 202
data:
class_path: HySpecNet11kDataModule
init_args:
batch_size: 2
dict_kwargs:
root: 'tests/data/hyspecnet'
13 changes: 13 additions & 0 deletions tests/conf/treesatai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
model:
class_path: MultiLabelClassificationTask
init_args:
model: 'resnet18'
in_channels: 19
num_classes: 15
loss: 'bce'
data:
class_path: TreeSatAIDataModule
init_args:
batch_size: 1
dict_kwargs:
root: 'tests/data/treesatai'
61 changes: 61 additions & 0 deletions tests/data/hyspecnet/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import os
import shutil

import numpy as np
import rasterio
from rasterio import Affine
from rasterio.crs import CRS

SIZE = 32
DTYPE = 'int16'

np.random.seed(0)

# Tile name purposefully shortened to avoid Windows git filename length limit.
tiles = ['ENMAP01_20221103T162438Z']
patches = ['Y01460273_X05670694', 'Y01460273_X06950822']

profile = {
'driver': 'GTiff',
'dtype': DTYPE,
'nodata': -32768.0,
'width': SIZE,
'height': SIZE,
'count': 224,
'crs': CRS.from_epsg(32618),
'transform': Affine(30.0, 0.0, 691845.0, 0.0, -30.0, 4561935.0),
'blockysize': 3,
'tiled': False,
'compress': 'deflate',
'interleave': 'band',
}

root = 'hyspecnet-11k'
path = os.path.join(root, 'splits', 'easy')
os.makedirs(path, exist_ok=True)
for tile in tiles:
for patch in patches:
# Split CSV
path = os.path.join(tile, f'{tile}-{patch}', f'{tile}-{patch}-DATA.npy')
for split in ['train', 'val', 'test']:
with open(os.path.join(root, 'splits', 'easy', f'{split}.csv'), 'a+') as f:
f.write(f'{path}\n')

# Spectral image
path = os.path.join(root, 'patches', path)
os.makedirs(os.path.dirname(path), exist_ok=True)
path = path.replace('DATA.npy', 'SPECTRAL_IMAGE.TIF')
Z = np.random.randint(
np.iinfo(DTYPE).min, np.iinfo(DTYPE).max, size=(SIZE, SIZE), dtype=DTYPE
)
with rasterio.open(path, 'w', **profile) as src:
for i in range(1, profile['count'] + 1):
src.write(Z, i)

shutil.make_archive(f'{root}-01', 'gztar', '.', os.path.join(root, 'patches'))
shutil.make_archive(f'{root}-splits', 'gztar', '.', os.path.join(root, 'splits'))
Binary file added tests/data/hyspecnet/hyspecnet-11k-01.tar.gz
Binary file not shown.
Binary file added tests/data/hyspecnet/hyspecnet-11k-splits.tar.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/data/hyspecnet/hyspecnet-11k/splits/easy/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X05670694/ENMAP01_20221103T162438Z-Y01460273_X05670694-DATA.npy
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X06950822/ENMAP01_20221103T162438Z-Y01460273_X06950822-DATA.npy
2 changes: 2 additions & 0 deletions tests/data/hyspecnet/hyspecnet-11k/splits/easy/train.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X05670694/ENMAP01_20221103T162438Z-Y01460273_X05670694-DATA.npy
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X06950822/ENMAP01_20221103T162438Z-Y01460273_X06950822-DATA.npy
2 changes: 2 additions & 0 deletions tests/data/hyspecnet/hyspecnet-11k/splits/easy/val.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X05670694/ENMAP01_20221103T162438Z-Y01460273_X05670694-DATA.npy
ENMAP01_20221103T162438Z/ENMAP01_20221103T162438Z-Y01460273_X06950822/ENMAP01_20221103T162438Z-Y01460273_X06950822-DATA.npy
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/treesatai/aerial_60m_alnus_spec.zip
Binary file not shown.
Binary file not shown.
Binary file added tests/data/treesatai/aerial_60m_picea_abies.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/treesatai/aerial_60m_quercus_rubra.zip
Binary file not shown.
129 changes: 129 additions & 0 deletions tests/data/treesatai/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env python3

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import glob
import json
import os
import random
import shutil
import zipfile

import numpy as np
import rasterio
from rasterio import Affine
from rasterio.crs import CRS

SIZE = 32

random.seed(0)
np.random.seed(0)

classes = (
'Abies',
'Acer',
'Alnus',
'Betula',
'Cleared',
'Fagus',
'Fraxinus',
'Larix',
'Picea',
'Pinus',
'Populus',
'Prunus',
'Pseudotsuga',
'Quercus',
'Tilia',
)

species = (
'Acer_pseudoplatanus',
'Alnus_spec',
'Fagus_sylvatica',
'Picea_abies',
'Pseudotsuga_menziesii',
'Quercus_petraea',
'Quercus_rubra',
)

profile = {
'aerial': {
'driver': 'GTiff',
'dtype': 'uint8',
'nodata': None,
'width': SIZE,
'height': SIZE,
'count': 4,
'crs': CRS.from_epsg(25832),
'transform': Affine(
0.19999999999977022, 0.0, 552245.4, 0.0, -0.19999999999938728, 5728215.0
),
},
's1': {
'driver': 'GTiff',
'dtype': 'float32',
'nodata': -9999.0,
'width': SIZE // 16,
'height': SIZE // 16,
'count': 3,
'crs': CRS.from_epsg(32632),
'transform': Affine(10.0, 0.0, 552245.0, 0.0, -10.0, 5728215.0),
},
's2': {
'driver': 'GTiff',
'dtype': 'uint16',
'nodata': None,
'width': SIZE // 16,
'height': SIZE // 16,
'count': 12,
'crs': CRS.from_epsg(32632),
'transform': Affine(10.0, 0.0, 552241.6565, 0.0, -10.0, 5728211.6251),
},
}

multi_labels = {}
for split in ['train', 'test']:
with open(f'{split}_filenames.lst') as f:
for filename in f:
filename = filename.strip()
for sensor in ['aerial', 's1', 's2']:
kwargs = profile[sensor]
directory = os.path.join(sensor, '60m')
os.makedirs(directory, exist_ok=True)
if 'int' in kwargs['dtype']:
Z = np.random.randint(
np.iinfo(kwargs['dtype']).min,
np.iinfo(kwargs['dtype']).max,
size=(kwargs['height'], kwargs['width']),
dtype=kwargs['dtype'],
)
else:
Z = np.random.rand(kwargs['height'], kwargs['width'])

path = os.path.join(directory, filename)
with rasterio.open(path, 'w', **kwargs) as src:
for i in range(1, kwargs['count'] + 1):
src.write(Z, i)

k = random.randrange(1, 4)
labels = random.choices(classes, k=k)
pcts = np.random.rand(k)
pcts /= np.sum(pcts)
multi_labels[filename] = list(map(list, zip(labels, map(float, pcts))))

os.makedirs('labels', exist_ok=True)
path = os.path.join('labels', 'TreeSatBA_v9_60m_multi_labels.json')
with open(path, 'w') as f:
json.dump(multi_labels, f)

for sensor in ['s1', 's2', 'labels']:
shutil.make_archive(sensor, 'zip', '.', sensor)

for spec in species:
path = f'aerial_60m_{spec}.zip'.lower()
with zipfile.ZipFile(path, 'w') as f:
for path in glob.iglob(os.path.join('aerial', '60m', f'{spec}_*.tif')):
filename = os.path.split(path)[-1]
f.write(path, arcname=filename)
Binary file added tests/data/treesatai/labels.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Picea_abies_3_46636_WEFL_NLF.tif": [["Prunus", 0.20692122963708826], ["Fraxinus", 0.7930787703629117]], "Pseudotsuga_menziesii_1_339575_BI_NLF.tif": [["Tilia", 0.4243067837573989], ["Larix", 0.5756932162426011]], "Quercus_rubra_1_92184_WEFL_NLF.tif": [["Tilia", 0.5816157697641007], ["Fagus", 0.4183842302358993]], "Fagus_sylvatica_9_29995_WEFL_NLF.tif": [["Larix", 1.0]], "Quercus_petraea_5_80549_WEFL_NLF.tif": [["Alnus", 0.5749721529276662], ["Acer", 0.4250278470723338]], "Acer_pseudoplatanus_3_5758_WEFL_NLF.tif": [["Tilia", 0.8430361090251272], ["Larix", 0.1569638909748729]], "Alnus_spec._5_13114_WEFL_NLF.tif": [["Pseudotsuga", 0.17881149698366108], ["Quercus", 0.38732907538618866], ["Cleared", 0.4338594276301503]], "Quercus_petraea_2_84375_WEFL_NLF.tif": [["Acer", 0.3909090505343164], ["Pseudotsuga", 0.2628926194326892], ["Cleared", 0.34619833003299444]], "Picea_abies_2_46896_WEFL_NLF.tif": [["Acer", 0.4953810312272686], ["Fraxinus", 0.0006659055704136941], ["Pinus", 0.5039530632023177]], "Acer_pseudoplatanus_4_6058_WEFL_NLF.tif": [["Tilia", 1.0]]}
Binary file added tests/data/treesatai/s1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/data/treesatai/s2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/treesatai/test_filenames.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Acer_pseudoplatanus_4_6058_WEFL_NLF.tif
9 changes: 9 additions & 0 deletions tests/data/treesatai/train_filenames.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Picea_abies_3_46636_WEFL_NLF.tif
Pseudotsuga_menziesii_1_339575_BI_NLF.tif
Quercus_rubra_1_92184_WEFL_NLF.tif
Fagus_sylvatica_9_29995_WEFL_NLF.tif
Quercus_petraea_5_80549_WEFL_NLF.tif
Acer_pseudoplatanus_3_5758_WEFL_NLF.tif
Alnus_spec._5_13114_WEFL_NLF.tif
Quercus_petraea_2_84375_WEFL_NLF.tif
Picea_abies_2_46896_WEFL_NLF.tif
Loading

0 comments on commit fa4b8f8

Please sign in to comment.