-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add yaml and modify/test for training
- Loading branch information
Showing
7 changed files
with
136 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module: | ||
_target_: torchgeo.trainers.SemanticSegmentationTask | ||
model: "unet" | ||
backbone: "resnet18" | ||
weights: null | ||
in_channels: 12 | ||
num_classes: 13 | ||
loss: "ce" | ||
ignore_index: 0 | ||
learning_rate: 1e-3 | ||
learning_rate_schedule_patience: 6 | ||
weight_decay: 0 | ||
|
||
datamodule: | ||
_target_: torchgeo.datamodules.AgriFieldNetDataModule | ||
root: "data" | ||
batch_size: 64 | ||
patch_size: 256 | ||
num_workers: 10 | ||
|
||
trainer: | ||
_target_: lightning.pytorch.Trainer | ||
min_epochs: 1 | ||
max_epochs: 2 | ||
|
||
program: | ||
seed: 2 | ||
output_dir: "output/agrifieldnet" | ||
log_dir: "logs/agrifieldnet" | ||
overwrite: True | ||
experiment_name: agrifieldnet |
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,78 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
"""Runs the train script with a grid of hyperparameters.""" | ||
import itertools | ||
import os | ||
import subprocess | ||
from multiprocessing import Process, Queue | ||
|
||
# list of GPU IDs that we want to use, one job will be started for every ID in the list | ||
GPUS = [0] | ||
DRY_RUN = False # if False then print out the commands to be run, if True then run | ||
conf_file_name = "agrifieldnet.yaml" | ||
|
||
# Hyperparameter options | ||
model_options = ["unet"] | ||
backbone_options = ["resnet18"] | ||
lr_options = [0.001, 0.0003, 0.0001, 0.00003] | ||
loss_options = ["ce"] | ||
weight_options = [False] | ||
seed_options = [2] | ||
weight_decay_options = [0] | ||
|
||
|
||
def do_work(work: "Queue[str]", gpu_idx: int) -> bool: | ||
"""Process for each ID in GPUS.""" | ||
while not work.empty(): | ||
experiment = work.get() | ||
experiment = experiment.replace("GPU", str(gpu_idx)) | ||
print(experiment) | ||
if not DRY_RUN: | ||
subprocess.call(experiment.split(" ")) | ||
return True | ||
|
||
|
||
if __name__ == "__main__": | ||
work: "Queue[str]" = Queue() | ||
|
||
for model, backbone, lr, loss, weights, weight_decay, seed in itertools.product( | ||
model_options, | ||
backbone_options, | ||
lr_options, | ||
loss_options, | ||
weight_options, | ||
weight_decay_options, | ||
seed_options, | ||
): | ||
if model == "fcn" and not weights: | ||
continue | ||
|
||
experiment_name = f"{conf_file_name.split('.')[0]}_{model}_{backbone}_{lr}_{loss}_{weights}_{weight_decay}_{seed}" | ||
|
||
config_file = os.path.join("conf", conf_file_name) | ||
|
||
command = ( | ||
"python train.py" | ||
+ f" config_file={config_file}" | ||
+ f" module.model={model}" | ||
+ f" module.backbone={backbone}" | ||
+ f" module.learning_rate={lr}" | ||
+ f" module.loss={loss}" | ||
+ f" module.weights={weights}" | ||
+ f" program.experiment_name={experiment_name}" | ||
+ f" program.seed={seed}" | ||
+ " trainer.devices=[GPU]" | ||
) | ||
command = command.strip() | ||
|
||
work.put(command) | ||
|
||
processes = [] | ||
for gpu_idx in GPUS: | ||
p = Process(target=do_work, args=(work, gpu_idx)) | ||
processes.append(p) | ||
p.start() | ||
for p in processes: | ||
p.join() |
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
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