forked from eloimoliner/BABE2-music-restoration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
65 lines (50 loc) · 1.98 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
import os
import re
import json
import hydra
import torch
#from utils.torch_utils import distributed as dist
import utils.setup as setup
import copy
def _main(args):
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
clean_path = args.dset.clean_path
noisy_path = args.dset.noisy_path
dset = setup.setup_dataset(clean_path, noisy_path, args)
#assert torch.cuda.is_available()
#device="cuda"
global __file__
__file__ = hydra.utils.to_absolute_path(__file__)
dirname = os.path.dirname(__file__)
args.model_dir = os.path.join(dirname, str(args.model_dir))
if not os.path.exists(args.model_dir):
os.makedirs(args.model_dir)
args.exp.model_dir=args.model_dir
#dist.init()
dset=setup.setup_dataset(args)
diff_params=setup.setup_diff_parameters(args)
network=setup.setup_network(args, device)
optimizer=setup.setup_optimizer(args, network)
network_tester=copy.deepcopy(network)
tester=setup.setup_tester(args, network=network_tester, diff_params=diff_params, device=device) #this will be used for making demos during training
print("setting up trainer")
trainer=setup.setup_trainer(args, dset=dset, network=network, optimizer=optimizer, diff_params=diff_params, tester=tester, device=device) #this will be used for making demos during training
print("trainer set up")
# Print options.
print()
print('Training options:')
print()
print(f'Output directory: {args.model_dir}')
print(f'Network architecture: {args.network.callable}')
print(f'Dataset: {args.dset.callable}')
print(f'Diffusion parameterization: {args.diff_params.callable}')
print(f'Batch size: {args.exp.batch}')
print()
# Train.
trainer.training_loop()
@hydra.main(config_path="conf", config_name="conf_piano")
def main(args):
_main(args)
if __name__ == "__main__":
main()
# ----------------------------------------------------------------------------