-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
56 lines (37 loc) · 1.41 KB
/
run.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
import logging
import warnings
import hydra
import random
import torch
from omegaconf import DictConfig
from pytorch_lightning import seed_everything
from dotenv import load_dotenv
log = logging.getLogger(__name__)
load_dotenv('.env')
hydra.core.global_hydra.GlobalHydra.instance().clear()
@hydra.main(config_path="configs", config_name="train", version_base="1.2")
def main(config: DictConfig) -> None:
from src import utils, train, visualize, prepare_data, test_cnn, unet_visualize
if config.seed == -1:
config.seed = random.randint(0, 10 ** 8)
seed_everything(config.seed)
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
torch.backends.cudnn.determinstic = True
torch.backends.cudnn.benchmark = False
if config.get("print_config"):
utils.print_config(config, fields=tuple(config.keys()), resolve=True)
if config.get("ignore_warnings"):
log.info("Disabling python warnings! <config.ignore_warnings=True>")
warnings.filterwarnings("ignore")
if config.name == "prepare_data":
return prepare_data(config)
if config.name == "train":
return train(config)
if config.name == "visualize":
return visualize(config)
if config.name == "test_cnn":
return test_cnn(config)
if config.name == "unet_visualize":
return unet_visualize(config)
if __name__ == '__main__':
main()