-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from nasa-nccs-hpda/finetuning
Added initial finetuning
- Loading branch information
Showing
23 changed files
with
1,034 additions
and
81 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
33 changes: 33 additions & 0 deletions
33
examples/satvision/finetune_satvision_base_landcover5class_192_window12_100ep.yaml
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,33 @@ | ||
MODEL: | ||
TYPE: swinv2 | ||
DECODER: unet | ||
NAME: satvision_finetune_lc5class | ||
DROP_PATH_RATE: 0.1 | ||
NUM_CLASSES: 5 | ||
SWINV2: | ||
IN_CHANS: 7 | ||
EMBED_DIM: 128 | ||
DEPTHS: [ 2, 2, 18, 2 ] | ||
NUM_HEADS: [ 4, 8, 16, 32 ] | ||
WINDOW_SIZE: 14 | ||
PRETRAINED_WINDOW_SIZES: [ 12, 12, 12, 6 ] | ||
DATA: | ||
IMG_SIZE: 224 | ||
DATASET: MODISLC5 | ||
MASK_PATCH_SIZE: 32 | ||
MASK_RATIO: 0.6 | ||
LOSS: | ||
NAME: 'tversky' | ||
MODE: 'multiclass' | ||
ALPHA: 0.4 | ||
BETA: 0.6 | ||
TRAIN: | ||
EPOCHS: 100 | ||
WARMUP_EPOCHS: 10 | ||
BASE_LR: 1e-4 | ||
WARMUP_LR: 5e-7 | ||
WEIGHT_DECAY: 0.01 | ||
LAYER_DECAY: 0.8 | ||
PRINT_FREQ: 100 | ||
SAVE_FREQ: 5 | ||
TAG: satvision_finetune_land_cover_5class_swinv2_satvision_192_window12__800ep |
33 changes: 33 additions & 0 deletions
33
examples/satvision/finetune_satvision_base_landcover9class_192_window12_100ep.yaml
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,33 @@ | ||
MODEL: | ||
TYPE: swinv2 | ||
DECODER: unet | ||
NAME: satvision_finetune_lc9class | ||
DROP_PATH_RATE: 0.1 | ||
NUM_CLASSES: 9 | ||
SWINV2: | ||
IN_CHANS: 7 | ||
EMBED_DIM: 128 | ||
DEPTHS: [ 2, 2, 18, 2 ] | ||
NUM_HEADS: [ 4, 8, 16, 32 ] | ||
WINDOW_SIZE: 14 | ||
PRETRAINED_WINDOW_SIZES: [ 12, 12, 12, 6 ] | ||
DATA: | ||
IMG_SIZE: 224 | ||
DATASET: MODISLC5 | ||
MASK_PATCH_SIZE: 32 | ||
MASK_RATIO: 0.6 | ||
LOSS: | ||
NAME: 'tversky' | ||
MODE: 'multiclass' | ||
ALPHA: 0.4 | ||
BETA: 0.6 | ||
TRAIN: | ||
EPOCHS: 100 | ||
WARMUP_EPOCHS: 10 | ||
BASE_LR: 1e-4 | ||
WARMUP_LR: 5e-7 | ||
WEIGHT_DECAY: 0.01 | ||
LAYER_DECAY: 0.8 | ||
PRINT_FREQ: 100 | ||
SAVE_FREQ: 5 | ||
TAG: satvision_finetune_land_cover_9class_swinv2_satvision_192_window12__800ep |
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,20 @@ | ||
#!/bin/bash | ||
|
||
#SBATCH -J finetune_satvision_lc5 | ||
#SBATCH -t 3-00:00:00 | ||
#SBATCH -G 4 | ||
#SBATCH -N 1 | ||
|
||
|
||
export PYTHONPATH=$PWD:../../../:../../../pytorch-caney | ||
export NGPUS=8 | ||
|
||
torchrun --nproc_per_node $NGPUS \ | ||
../../../pytorch-caney/pytorch_caney/pipelines/finetuning/finetune.py \ | ||
--cfg finetune_satvision_base_landcover5class_192_window12_100ep.yaml \ | ||
--pretrained /explore/nobackup/people/cssprad1/projects/satnet/code/development/masked_image_modeling/development/models/simmim_satnet_pretrain_pretrain/simmim_pretrain__satnet_swinv2_base__img192_window12__800ep_v3_no_norm/ckpt_epoch_800.pth \ | ||
--dataset MODISLC9 \ | ||
--data-paths /explore/nobackup/projects/ilab/data/satvision/finetuning/h18v04/labels_9classes_224 \ | ||
--batch-size 4 \ | ||
--output /explore/nobackup/people/cssprad1/projects/satnet/code/development/cleanup/finetune/models \ | ||
--enable-amp |
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,20 @@ | ||
#!/bin/bash | ||
|
||
#SBATCH -J finetune_satvision_lc9 | ||
#SBATCH -t 3-00:00:00 | ||
#SBATCH -G 4 | ||
#SBATCH -N 1 | ||
|
||
|
||
export PYTHONPATH=$PWD:../../../:../../../pytorch-caney | ||
export NGPUS=8 | ||
|
||
torchrun --nproc_per_node $NGPUS \ | ||
../../../pytorch-caney/pytorch_caney/pipelines/finetuning/finetune.py \ | ||
--cfg finetune_satvision_base_landcover5class_192_window12_100ep.yaml \ | ||
--pretrained /explore/nobackup/people/cssprad1/projects/satnet/code/development/masked_image_modeling/development/models/simmim_satnet_pretrain_pretrain/simmim_pretrain__satnet_swinv2_base__img192_window12__800ep_v3_no_norm/ckpt_epoch_800.pth \ | ||
--dataset MODISLC9 \ | ||
--data-paths /explore/nobackup/projects/ilab/data/satvision/finetuning/h18v04/labels_5classes_224 \ | ||
--batch-size 4 \ | ||
--output /explore/nobackup/people/cssprad1/projects/satnet/code/development/cleanup/finetune/models \ | ||
--enable-amp |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from ..datasets.modis_dataset import MODISDataset | ||
from ..datasets.modis_lc_five_dataset import MODISLCFiveDataset | ||
from ..datasets.modis_lc_nine_dataset import MODISLCNineDataset | ||
|
||
from ..transforms import TensorResizeTransform | ||
|
||
import torch.distributed as dist | ||
from torch.utils.data import DataLoader, DistributedSampler | ||
|
||
|
||
DATASETS = { | ||
'modis': MODISDataset, | ||
'modislc9': MODISLCNineDataset, | ||
'modislc5': MODISLCFiveDataset, | ||
# 'modis tree': MODISTree, | ||
} | ||
|
||
|
||
def get_dataset_from_dict(dataset_name: str): | ||
|
||
dataset_name = dataset_name.lower() | ||
|
||
try: | ||
|
||
dataset_to_use = DATASETS[dataset_name] | ||
|
||
except KeyError: | ||
|
||
error_msg = f"{dataset_name} is not an existing dataset" | ||
|
||
error_msg = f"{error_msg}. Available datasets: {DATASETS.keys()}" | ||
|
||
raise KeyError(error_msg) | ||
|
||
return dataset_to_use | ||
|
||
|
||
def build_finetune_dataloaders(config, logger): | ||
|
||
transform = TensorResizeTransform(config) | ||
|
||
logger.info(f'Finetuning data transform:\n{transform}') | ||
|
||
dataset_name = config.DATA.DATASET | ||
|
||
logger.info(f'Dataset: {dataset_name}') | ||
logger.info(f'Data Paths: {config.DATA.DATA_PATHS}') | ||
|
||
dataset_to_use = get_dataset_from_dict(dataset_name) | ||
|
||
logger.info(f'Dataset obj: {dataset_to_use}') | ||
|
||
dataset_train = dataset_to_use(data_paths=config.DATA.DATA_PATHS, | ||
split="train", | ||
img_size=config.DATA.IMG_SIZE, | ||
transform=transform) | ||
|
||
dataset_val = dataset_to_use(data_paths=config.DATA.DATA_PATHS, | ||
split="val", | ||
img_size=config.DATA.IMG_SIZE, | ||
transform=transform) | ||
|
||
logger.info(f'Build dataset: train images = {len(dataset_train)}') | ||
|
||
logger.info(f'Build dataset: val images = {len(dataset_val)}') | ||
|
||
sampler_train = DistributedSampler( | ||
dataset_train, | ||
num_replicas=dist.get_world_size(), | ||
rank=dist.get_rank(), | ||
shuffle=True) | ||
|
||
sampler_val = DistributedSampler( | ||
dataset_val, | ||
num_replicas=dist.get_world_size(), | ||
rank=dist.get_rank(), | ||
shuffle=False) | ||
|
||
dataloader_train = DataLoader(dataset_train, | ||
config.DATA.BATCH_SIZE, | ||
sampler=sampler_train, | ||
num_workers=config.DATA.NUM_WORKERS, | ||
pin_memory=True, | ||
drop_last=True) | ||
|
||
dataloader_val = DataLoader(dataset_val, | ||
config.DATA.BATCH_SIZE, | ||
sampler=sampler_val, | ||
num_workers=config.DATA.NUM_WORKERS, | ||
pin_memory=True, | ||
drop_last=False) | ||
|
||
return dataloader_train, dataloader_val |
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
Oops, something went wrong.