forked from platonic-realm/gbm-seg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
66 lines (50 loc) · 2.21 KB
/
train.py
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
# Python Imprts
import logging
# Library Imports
import torch
# Local Imports
from src.utils import args
from src.utils.misc import configure_logger
from src.utils.misc import summerize_configs
from src.train.factory import Factory
def main_train(_configs):
if _configs['logging']['log_summary']:
summerize_configs(_configs)
if _configs['trainer']['cudnn_benchmark']:
torch.backends.cudnn.benchmark = True
logging.info("Enabling cudnn benchmarking")
torch.manual_seed(88233474)
factory = Factory(_configs)
train_dataset = factory.createTrainDataset()
train_dataloader = factory.createTrainDataLoader(train_dataset)
valid_dataset = factory.createValidDataset()
valid_dataloader = factory.createValidDataLoader(valid_dataset)
model = factory.createModel(train_dataset.getNumberOfChannels(),
train_dataset.getNumberOfClasses())
loss_function = factory.createLoss()
optimizer = factory.createOptimizer(model)
lr_scheduler = factory.createScheduler(optimizer)
stepper = factory.createStepper(model, optimizer, loss_function)
snapper = factory.createSnapper()
visualizer = factory.createVisualizer()
profiler = factory.createProfiler()
metric_logger = factory.createMetricLogger(model,
valid_dataloader,
loss_function,
train_dataset.getNumberOfClasses())
trainer = factory.createTrainer(model,
loss_function,
stepper,
snapper,
profiler,
visualizer,
metric_logger,
lr_scheduler,
train_dataloader,
valid_dataloader,
train_dataset.getNumberOfClasses())
trainer.train()
if __name__ == '__main__':
_, configs = args.parse_indep("Training Unet3D for GBM segmentation")
configure_logger(configs)
main_train(configs)