-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_covid.py
49 lines (36 loc) · 1.36 KB
/
runner_covid.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
from save_to_csv import save_results
import logging
import sys
import utils.multiprocessing
from defaults import get_cfg_defaults
import os
full_run = False
logger = logging.getLogger("logger")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(stream=sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s: %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
if len(sys.argv) > 1:
cfg_file = 'configs/' + sys.argv[1]
else:
cfg_file = 'configs/covid_1.yaml'
cfg = get_cfg_defaults()
cfg.merge_from_file(cfg_file)
cfg.freeze()
def f(fold_id):
import train_alae
import novelty_detector
import torch
inliner_classes = 0
# torch.cuda.set_device(0)
# torch.set_default_tensor_type('torch.cuda.FloatTensor')
device = torch.cuda.current_device()
print("Running on ", torch.cuda.get_device_name(device))
train_alae.train(cfg=cfg, logger=logger, local_rank=device, world_size=1, folding_id=fold_id, inliner_classes=[inliner_classes])
res = novelty_detector.main(cfg=cfg, logger=logger, local_rank=device, folding_id=fold_id, inliner_classes=[inliner_classes])
return res
gpu_count = min(utils.multiprocessing.get_gpu_count(), 8)
results = utils.multiprocessing.map(f, gpu_count, list(range(gpu_count)))
save_results(results, os.path.join(cfg.OUTPUT_DIR, cfg.RESULTS_NAME))