File size: 7,780 Bytes
6e33b3b 27cc8da 6e33b3b d96879d 6e33b3b 27cc8da 6e33b3b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | """T-SRDA on MTLCC (data_IJGI18, 480 m / 48x48-px tiles) - configuration.
Protocol = the STCLN MTLCC scripts (STCLN/MTLCC/*.py), exactly as hardcoded
there. The T-SRDA architecture and ALL optimisation hyper-parameters are
kept identical to the PASTIS runs (see TSRDA/main_method/code/*config.py);
only dataset-dependent values change. [STCLN-MTLCC] = value taken verbatim
from the STCLN MTLCC scripts. [TSRDA] = unchanged from the PASTIS run.
"""
import os
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent
DATA_ROOT = Path(os.environ.get("MTLCC_ROOT", "/home/ubuntu/pro/MTLCC_data"))
EXP_ROOT = Path(os.environ.get("EXP_ROOT", REPO_ROOT.parent / "runs"))
CKPT_DIR_PRE = EXP_ROOT / "checkpoints" / "pretrain"
CKPT_DIR_FT = EXP_ROOT / "checkpoints" / "finetune"
TRAIN_YEAR_DIR = "data16" # [STCLN-MTLCC] 2016 observations
DATA_DIR = DATA_ROOT / TRAIN_YEAR_DIR
TILEID_DIR = DATA_ROOT / "tileids"
CLASSES_TXT = DATA_ROOT / "classes.txt"
SEQLEN = 30 # [STCLN-MTLCC] ijgiDataset(seqlength=30): 30 random dates, sorted
REFLECTANCE_SCALE = 1e-4 # [STCLN-MTLCC] x * 1e-4, NO per-band normalisation
NORMALIZE = False
SEED = 3407 # [STCLN-MTLCC] torch.manual_seed(3407) [TSRDA] same
VARIANCE_SEEDS = (3407, 42, 1234)
# ---- architecture (unchanged from PASTIS run) -------------------------------
N_CHANNELS = 13 # [STCLN-MTLCC] 4(10m)+6(20m)+3(60m) bands
D_MODEL = 256 # [TSRDA]
N_HEADS = 8 # [TSRDA]
T_PAD = 48 # [TSRDA] inert
# [TSRDA] reduction factor of the three temporal SRDA blocks. Overridable only so the
# ablation "what does the spatial reduction cost?" can be run (R=1 is full-resolution
# keys/values, i.e. ordinary self-attention on the KV path). R changes the shape of each
# block's point-wise projection, so a run with a non-default R cannot load an encoder
# pre-trained at R=4 and must be trained from scratch; the queue pairs it with a
# from-scratch R=4 run so the two are comparable. Default is unchanged.
R_SCHEDULE = [int(x) for x in os.environ.get("R_SCHEDULE", "4,4,4").split(",")]
TSE_WINDOWS = [4, 8, 16]
TSE_SHIFTS = [0, 4, 0]
def _read_classes():
ids, names = [], []
if CLASSES_TXT.is_file():
for row in CLASSES_TXT.read_text().splitlines():
if "|" in row:
i, n = row.split("|", 1); ids.append(int(i)); names.append(n.strip())
return ids, names
CLASS_IDS, CLASS_NAMES = _read_classes()
N_CLASSES = len(CLASS_IDS) if CLASS_IDS else 18 # [STCLN-MTLCC] n_classes=18 (index 0 = background/ignored)
VOID = None # MTLCC has no void label; only index 0 is ignored
N_SCORED = N_CLASSES - 1 # classes 1..N-1 are scored
# ---- geometry ---------------------------------------------------------------
PATCH_SIZE = 48 # whole 48x48 tile is the unit (no cropping in STCLN-MTLCC)
CROP_SIZE = 48
PRETRAIN_CROP_GRID = 1
FT_CROP_IJ = [(0, 0)]
USE_INDEX_POSITIONS = True # model is fed arange(30) (STCLN passes range(30)/range(T))
# ---- pretraining ------------------------------------------------------------
PRETRAIN_TILEIDS = "train_fold0.tileids" # [STCLN-MTLCC] whole train_fold0, unlabelled
PRE_EPOCHS = 100 # [TSRDA] = [STCLN]
PRE_BATCH = 4 # [TSRDA] = [STCLN-MTLCC] default batch 4
PRE_LR = 1e-4
PRE_WD = 0.0
PRE_CLIP = 5.0
# [STCLN-MTLCC] the released pretraining script loops `for maskR in [0.15]`, which is the
# default kept here. The STCLN *paper* states 40 % ("we randomly mask 40 % of the pixels")
# and recommends 0.4 as the optimum (its Fig. 12), and the released MTLCC checkpoint path in
# finetuning_STCLN.py is .../batchtimespace0.4/checkpoint_99.utae.tar, i.e. the authors' own
# weights were pretrained at 0.4. Our PASTIS run also used 0.4. Override with MASK_RATIO=0.4
# to reproduce the paper's setting; the default is left at the script value for continuity.
MASK_RATIO = float(os.environ.get("MASK_RATIO", 0.15))
NDVI_THRESH = 0.2 # [STCLN-MTLCC] .gt(0.2)
CLOUD_GATE = 0.9 # [STCLN-MTLCC] mask[clusterLmean <= 0.9] = 1
# STCLN-MTLCC computes (x[:,:,3]-x[:,:,0])/(x[:,:,3]+x[:,:,0]) on the 13-band stack
# (band order x10,x20,x60 = B2,B3,B4,B8 | B5,B6,B7,B8A,B11,B12 | B1,B9,B10): index 3 = B8,
# index 0 = B2. Kept verbatim for comparability.
NDVI_NIR_IDX = 3
NDVI_RED_IDX = 0
PRE_SAVE_EVERY = 20
DEEP_SUP = False
# ---- fine-tuning ------------------------------------------------------------
FT_EPOCHS = 100
FT_BATCH = 2 # [STCLN-MTLCC] batch 2
FT_LR = 1e-4
FT_WD = 0.0
TRAIN_TILEIDS = "train_fold0.tileids" # sampling pool; actual tiles = hand-picked lists below
VAL_TILEIDS = "test_fold0.tileids"
TEST_TILEIDS = "eval.tileids" # [STCLN-MTLCC] test_STCLN.py
PER_CLASS_TILES = 6 # [STCLN-MTLCC] Train_collection[i][:3*2]
EVAL_BATCH = int(os.environ.get("EVAL_BATCH", 8))
EVAL_TTA = False
# [STCLN-MTLCC] finetuning_STCLN.py - hand-picked tiles, 13 classes x 15 candidates
_TR = {
1:[1175,8813,4325,6045,11503,7935,537,9423,7382,7849,14417,7315,2672,16422,3134],
2:[17003,13009,14073,14263,12921,13095,11037,12763,15142,10748,11597,16827,7984,12922,14794],
4:[1934,13112,1933,9336,4442,14860,13029,7929,10113,10659,10258,17815,15453,13119,13743],
5:[11473,11563,12164,11474,8175,10609,14527,8089,13657,11044,14528,10611,10248,11387,11476],
6:[1675,1762,7275,7382,3384,6428,17643,2431,9529,5325,10327,4645,1943,7532,10321],
7:[13738,11582,13396,9253,9430,8921,108,6422,14809,11423,4437,3241,5983,5986,6509],
8:[14327,17952,5243,15722,2929,14892,11523,13007,12622,14035,15809,7097,14793,17584,17174],
9:[15215,2359,10905,5334,5421,11436,5195,9299,11320,10202,11289,7065,4759,9386,7969],
10:[4686,10542,13750,6173,6512,12880,5303,5194,5982,5809,3287,6085,3636,4062,4673],
11:[10028,6857,14969,14883,6856,11349,11337,8893,11592,5757,536,11348,6800,14882,14944],
12:[3716,3802,3803,3894,3628,6172,2694,2488,4061,4325,6087,6870,3889,6694,6609],
15:[4511,6600,7560,8088,6426,5390,10895,8457,5391,5304,5998,7537,10802,13323,5394],
16:[7244,532,13054,11507,12618,4705,8018,7065,14161,7755,11589,7502,7927,11679,6104]}
_VA = {
1:[1007,14407,1976,920,929,6793,930,7777,1279,3316,5692,4015,10207,1744,1537],
2:[9575,11954,3839,4016,11629,16572,7888,9574,12265,17202,16575,1008,16553,16489,2885],
4:[4023,16242,10587,13718,12974,13634,13721,10763,13817,2253,13544,18257,16940,17115,1712],
5:[9481,9567,12262,10089,9305,10002,12088,12001,9550,9565,9913,9653,9463,9915,9219],
6:[1744,17288,9378,9218,1830,17201,6149,9379,9291,15500,5747,13812,1012,3927,5834],
7:[12019,5342,13812,6064,17506,17857,1919,12090,1834,9914,12020,5717,12004,5270,5343],
8:[12099,18345,16490,5863,8043,9392,13369,18432,1783,15412,12012,5346,10847,13814,13806],
9:[6148,18396,6127,5802,5714,12179,5952,5715,14116,5889,6124,18395,8153,6064,6062],
10:[12018,12369,834,9311,13419,11931,12282,14117,14028,6153,13504,12281,12095,9399,14203],
11:[17288,4025,4024,3147,1012,1016,12325,10297,14494,14493,12361,18396,4020,3060,929],
12:[5979,1966,9858,5892,1964,17288,4025,4024,3147,1012,1016,12325,10297,14494,14493],
15:[18345,5892,1104,9861,5803,5979,14320,13812,9478,5717,17284,16614,9288,5801,9391],
16:[1008,12627,9398,12107,11317,10208,9485,6793,9140,12190,6152,1976,10121,11315,12095]}
TRAIN_TILE_IDS = [t for k in _TR for t in _TR[k][:PER_CLASS_TILES]] # 78 entries (dups kept)
VAL_TILE_IDS = [t for k in _VA for t in _VA[k][:PER_CLASS_TILES]] # 78 entries (dups kept)
|