-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
66 lines (55 loc) · 1.59 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
import click
import os
import sys
import requests
import zipfile
import torch
class ModelArgs(dict):
def __init__(self, *args, **kwargs):
super(ModelArgs, self).__init__(*args, **kwargs)
self.__dict__ = self
def download_data_from_url():
"""Download data set."""
path = os.getcwd() + '/data/'
#Make directory for dataset
try:
os.mkdir(path)
except OSError:
sys.exit(f'Creation of directory {path} failed')
# Download dataset
url = 'https://zenodo.org/record/1117372/files/musdb18.zip?download=1'
filename = path + 'musdb18.zip'
r = requests.get(url, stream=True)
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=128):
f.write(chunk)
with zipfile.ZipFile(filename, 'r') as zipf:
zipf.extract(path)
@click.command()
@click.option('--download-data/--no-download-data',
default=False, help='Download data set, defaults to false.')
@click.option('--epochs', default=100,
help='Number of training epochs.')
@click.option('--lr', default=1e-3, help='Initial learning rate.')
@click.option('--cuda/--no-cuda', default=True,
help='Train on GPU if available.')
@click.option('--beta', nargs=2, type=(float, float),
help='Beta range for Adam optimizer.')
def main(download_data, epochs, lr, cuda, beta):
if download_data:
download_data_from_url()
if cuda:
if not torch.cuda.is_available():
print("Cuda not available")
return
device = torch.device('cuda')
args = ModelArgs({
'epochs': epochs,
'lr': lr,
'beta': beta,
'device': device
})
print(epochs, lr, beta, device, download_data)
return args
if __name__ == '__main__':
main()