forked from hannesk95/DINOV2GNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
param_configurator.py
73 lines (60 loc) · 2.84 KB
/
param_configurator.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
67
68
69
70
71
72
73
import configparser
import torch
import os
import uuid
class ParamConfigurator:
"""Parameter configurator class for deep learning pipeline."""
def __init__(self):
"""# TODO: Docstring"""
config = configparser.ConfigParser()
config.read('/home/johannes/Code/DINOV2GNN/config.ini')
# Global
self.seed = config['global'].getint('seed')
self.device = config['global']['device']
if self.device == 'cuda':
torch.cuda.empty_cache()
# Data
self.dataset = config['data']['dataset']
self.num_slices = config['data'].getint('num_slices')
self.fraction = config['data'].getfloat('fraction')
self.topology = config['data']['topology']
self.artifact_dir = config['data']['artifact_directory']
self.k = config['data'].getint("k")
# self.similarity_metric = config['data']['similarity_metric']
if not os.path.exists(self.artifact_dir):
os.mkdir(self.artifact_dir)
self.run_uuid = uuid.uuid4().hex
self.run_dir = os.path.join(os.path.abspath(self.artifact_dir), self.run_uuid)
if not os.path.exists(self.run_dir):
os.mkdir(self.run_dir)
else:
raise ValueError("Run dir does already exist!")
# Architecture
self.model_name = config['architecture']['model_name']
# self.model_output = config['architecture']['model_output']
# assert self.model_output in ['cls', 'max', 'mean']
self.hidden_channels = config['architecture'].getint('hidden_channels')
self.gnn_type = config['architecture']['gnn_type']
self.gnn_readout = config['architecture']['gnn_readout']
self.mlp_aggregation = config['architecture']['mlp_aggregation']
self.mlp_conditional = config['architecture'].getboolean('mlp_conditional')
match self.dataset:
case "fracture":
self.n_classes = 3
case "organ":
self.n_classes = 11
case _:
self.n_classes = 2
# Training
self.batch_size = config['training'].getint('batch_size')
self.epochs = config['training'].getint('epochs')
self.num_workers = config['training'].getint('num_workers')
self.ce_gamma = config['training'].getfloat('ce_gamma')
# Optimizer
self.learning_rate = config['optimizer'].getfloat('learning_rate')
self.optimizer = config['optimizer']['optimizer']
self.nesterov = config['optimizer'].getboolean('nesterov')
self.momentum = config['optimizer'].getfloat('momentum')
self.weight_decay = config['optimizer'].getfloat('weight_decay')
self.scheduler_gamma = config['optimizer'].getfloat('scheduler_gamma')
self.scheduler_step = config['optimizer'].getint('scheduler_step')