-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into added_tutorial
- Loading branch information
Showing
76 changed files
with
1,118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file added
BIN
+491 KB
...2438Z-Y01460273_X05670694/ENMAP01_20221103T162438Z-Y01460273_X05670694-SPECTRAL_IMAGE.TIF
Binary file not shown.
Binary file added
BIN
+491 KB
...2438Z-Y01460273_X06950822/ENMAP01_20221103T162438Z-Y01460273_X06950822-SPECTRAL_IMAGE.TIF
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+4.38 KB
tests/data/treesatai/aerial/60m/Acer_pseudoplatanus_3_5758_WEFL_NLF.tif
Binary file not shown.
Binary file added
BIN
+4.38 KB
tests/data/treesatai/aerial/60m/Acer_pseudoplatanus_4_6058_WEFL_NLF.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.38 KB
tests/data/treesatai/aerial/60m/Pseudotsuga_menziesii_1_339575_BI_NLF.tif
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file added
BIN
+450 Bytes
tests/data/treesatai/s1/60m/Acer_pseudoplatanus_3_5758_WEFL_NLF.tif
Binary file not shown.
Binary file added
BIN
+450 Bytes
tests/data/treesatai/s1/60m/Acer_pseudoplatanus_4_6058_WEFL_NLF.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+450 Bytes
tests/data/treesatai/s1/60m/Pseudotsuga_menziesii_1_339575_BI_NLF.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+538 Bytes
tests/data/treesatai/s2/60m/Acer_pseudoplatanus_3_5758_WEFL_NLF.tif
Binary file not shown.
Binary file added
BIN
+538 Bytes
tests/data/treesatai/s2/60m/Acer_pseudoplatanus_4_6058_WEFL_NLF.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+538 Bytes
tests/data/treesatai/s2/60m/Pseudotsuga_menziesii_1_339575_BI_NLF.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Acer_pseudoplatanus_4_6058_WEFL_NLF.tif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.