Siddarth commited on
Commit
d922c74
·
1 Parent(s): 3c89865

Upload Main.py

Browse files
Files changed (1) hide show
  1. Main.py +61 -0
Main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ # To speed-up training process
4
+ torch.autograd.set_detect_anomaly(False)
5
+ torch.autograd.profiler.profile(False)
6
+ torch.autograd.profiler.emit_nvtx(False)
7
+
8
+ import warnings
9
+ import pickle
10
+
11
+ from Transformer import Transformer
12
+ import librosa
13
+
14
+ import os.path as path
15
+ import json
16
+ from tqdm import tqdm
17
+ import time
18
+
19
+ import numpy as np
20
+
21
+ warnings.filterwarnings("ignore")
22
+
23
+ with open("config.json") as json_data_file:
24
+ data = json.load(json_data_file)
25
+
26
+ lr = data['learn_rate']
27
+ epochs = data['epochs']
28
+ batch_size = data['batch_size']
29
+ Training = data['Training']
30
+ Testing = data['Testing']
31
+ main_path = data['MainPath']
32
+
33
+ device = data['Device']
34
+ diag_attn = data['DiagAttn']
35
+
36
+ BestModelPath = 'Best_GlobalModel_500_0_0.pt'
37
+
38
+ def pre_process_mfcc(mfcc):
39
+
40
+ mfcc = mfcc.T
41
+
42
+ mean_G = np.mean(mfcc, axis=0)
43
+ std_G = np.std(mfcc, axis=0)
44
+ mfcc = 0.5*(mfcc-mean_G)/std_G
45
+
46
+ return mfcc
47
+
48
+ def wav2art(wav):
49
+ rate = 16000
50
+ mfcc = librosa.feature.mfcc(wav, 16000, n_mfcc=13, hop_length=int(0.010*rate), n_fft=int(0.020*rate))
51
+ mfcc = pre_process_mfcc(mfcc)
52
+
53
+ mfcc = torch.tensor([mfcc]).float()
54
+
55
+ test_model = torch.load(BestModelPath, map_location=torch.device('cpu')).float()
56
+ test_model.eval()
57
+
58
+ p = test_model(mfcc, 0, 0, 0)
59
+ p = p[0].detach().numpy()
60
+
61
+ return p