-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (49 loc) · 2.05 KB
/
main.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 sys
import torch
import AudioDataset
import GAN
import Pytorch_Classifier
import Pytorch_Generator
if __name__ == "__main__":
args = list(sys.argv)[1]
learning_rate = 0.0001
if args == "generator-train":
# Train a generator in a supervised manner
generator = Pytorch_Generator.Net()
criterion = Pytorch_Generator.SignalDistortionRatio()
device = torch.device("cuda")
generator.to(device)
criterion.to(device)
optimiser = torch.optim.Adam(generator.parameters(), lr=1)
generator.train_generator(optimiser, criterion, device)
elif args == "gan-train":
gan = GAN.GAN(learning_rate=0.000001)
gan.train()
elif args == "gan-generate":
generator = Pytorch_Generator.Net()
device = torch.device("cuda")
generator.to(device)
generator.load_state_dict(torch.load("generatorGANModel14.pt"))
generator.eval()
generator.generate(AudioDataset.NoisyMusicDataset(noisy_music_folder="ProcessedTest", folder_index=0),
"GANOutput")
elif args == "generator-generate":
generator = Pytorch_Generator.Net()
device = torch.device("cuda")
generator.to(device)
generator.load_state_dict(torch.load("generatorModel0.pt"))
generator.eval()
generator.generate(AudioDataset.NoisyMusicDataset(noisy_music_folder="ProcessedTest", folder_index=0),
"GeneratorOutputGen4")
elif args == "visualise-generator":
generator = Pytorch_Generator.Net()
generator.load_state_dict(torch.load("generatorModelNew1.pt"))
generator.eval()
x = torch.zeros(1, 1, 57330, dtype=torch.float, requires_grad=False)
out = generator(x)
elif args == "visualise-classifier":
classifier = Pytorch_Classifier.Net()
classifier.load_state_dict(torch.load("classifierGANModel.pt"))
classifier.eval()
x = torch.zeros(1, 2, 128, dtype=torch.float, requires_grad=False)
out = classifier(x)