-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet_impl.h
executable file
·139 lines (114 loc) · 7.67 KB
/
net_impl.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef NET_IMPL_H
#define NET_IMPL_H
#include <stdio.h>
#include <vector>
#include "wavernn.h"
const int RES_BLOCKS = 10;
const int UPSAMPLE_LAYERS = 3;
///
const int rnn_dims = 256;
const float posterior_size = 512.0 - 1.0;
const int subbands=4;
const int conv_trans_pad = 0;
const int conv_trans_ksize=4;
const int taps=31;
const int conv1d_pad = 0;
const int conv1d_ksize = 63;
const int conv1d_stride = 1;
const int n_aux = 128;
const int aux_dims = n_aux/4;
const int target = 4000; //4000
const int overlap = 200; //200
const int n_mel = 120;
Vectorf softmax( const Vectorf& x );
class ResBlock{
std::vector<TorchLayer> resblock;
public:
ResBlock() = default;
void loadNext( FILE* fd );
Matrixf apply( const Matrixf& x );
};
class Resnet{
TorchLayer conv_in;
TorchLayer batch_norm;
ResBlock resblock;
TorchLayer conv_out;
TorchLayer stretch2d; //moved stretch2d layer into resnet from upsample as in python code
public:
Resnet() = default;
void loadNext( FILE* fd );
Matrixf apply( const Matrixf& x );
};
class UpsampleNetwork{
std::vector<TorchLayer> up_layers;
public:
UpsampleNetwork() = default;
void loadNext( FILE* fd );
Matrixf apply( const Matrixf& x );
};
class Model{
struct Header{
int num_res_blocks;
int num_upsample;
int total_scale;
int nPad ;
};
Header header;
UpsampleNetwork upsample;
Resnet resnet;
TorchLayer I;
TorchLayer rnn1;
//
TorchLayer rnn2;
//
TorchLayer fc1;
TorchLayer fc2;
//
TorchLayer O1;
TorchLayer O2;
TorchLayer O3;
TorchLayer O4;
//
//TorchLayer fc3;
//
public:
Model() = default;
void loadNext( FILE* fd );
Vectorf apply( const Matrixf& x );
};
//4*63
static const float synthesis_filter[252] = {
1.6410407624789514e-05, 5.2573592256521806e-05, 8.409668953390792e-05, 6.816652603447437e-05, 1.0740955076471437e-05, 3.366634700796567e-05, 0.00033252930734306574, 0.000978455995209515,
0.0017008084105327725, 0.0019280391279608011, 0.0012425485765561461, -8.934543232307763e-19, -0.0005072396597824991, 0.001165855210274458, 0.005162402521818876, 0.009370473213493824,
0.010250899009406567, 0.0055413078516721725, -0.002920969156548381, -0.0089566083624959, -0.005798950791358948, 0.007897437550127506, 0.024309569969773293, 0.029186632484197617,
0.011209878139197826, -0.02739386074244976, -0.06699131429195404, -0.07833780348300934, -0.03929368034005165, 0.049359146505594254, 0.15986312925815582, 0.24944087862968445,
0.2822170555591583, 0.248145192861557, 0.1674685776233673, 0.07833780348300934, 0.015718381851911545, -0.005448977462947369, 0.0063498858362436295, 0.029186632484197617,
0.042915306985378265, 0.03970310091972351, 0.024714969098567963, 0.0089566083624959, 0.0006853561499156058, 0.0011022347025573254, 0.005806668195873499, 0.009370473213493824,
0.009113534353673458, 0.00586114963516593, 0.002161841606721282, 8.934543232307763e-19, -0.00029154305229894817, 0.00038351083640009165, 0.0009634306188672781, 0.000978455995209515,
0.0005870361928828061, 0.00016925214731600136, -4.577765503199771e-05, -6.816652603447437e-05, -1.9731869542738423e-05, 1.0457537428010255e-05, 9.295748895965517e-06, -1.391207206324907e-05,
-4.4569740566657856e-05, 1.9731869542738423e-05, 0.00012033892562612891, 3.05876528727822e-05, 9.587364183971658e-05, 0.0005870361928828061, 0.00022957818873692304, -0.0014418758219107985,
-0.001634512678720057, 0.00029154305229894817, -1.5772747128585902e-18, -0.0014444963308051229, 0.003320074640214443, 0.009113534353673458, 0.0021986234933137894, -0.008690292946994305,
-0.004697693977504969, -0.0006853561499156058, -0.015811698511242867, -0.016514014452695847, 0.02249000035226345, 0.042915306985378265, 0.006848150864243507, -0.009503276087343693,
0.0232233926653862, -0.015718381851911545, -0.13829496502876282, -0.11189892888069153, 0.14056296646595, 0.2822170555591583, 0.05852709710597992, -0.23925207555294037,
-0.2103673368692398, 0.03929368034005165, 0.13829496502876282, 0.04476216807961464, -0.01551737543195486, 0.011209878139197826, 0.006848150864243507, -0.03638184070587158,
-0.03365866467356682, 0.005798950791358948, 0.015811698511242867, 0.001951729180291295, 0.0031388988718390465, 0.010250899009406567, 0.0021986234933137894, -0.007726081181317568,
-0.0049688429571688175, 0.0005072396597824991, 1.5772747128585902e-18, -0.0008302443893626332, 0.0010921465000137687, 0.0017008084105327725, 0.00022957818873692304, -0.0004976652562618256,
-0.00014348504191730171, -1.0740955076471437e-05, -0.00012033892562612891, -5.619160947389901e-05, 2.9780547265545465e-05, 1.6410407624789514e-05, -9.295748895965517e-06, -2.9780547265545465e-05,
9.919880540110171e-05, -2.393690010649152e-05, -4.577765503199771e-05, -0.00014348504191730171, -0.000116768766019959, 0.0011541674612089992, -0.0009634306188672781, -0.0010921465000137687,
0.001465685898438096, 3.137394475294655e-19, 0.002161841606721282, -0.0049688429571688175, -0.0018127945950254798, 0.011053226888179779, -0.005806668195873499, -0.0031388988718390465,
-0.003445517970249057, 0.0031451424583792686, 0.024714969098567963, -0.03365866467356682, -0.008536385372281075, 0.034427981823682785, -0.0063498858362436295, 0.01551737543195486,
-0.0790216475725174, 0.027508579194545746, 0.1674685776233673, -0.2103673368692398, -0.05613646283745766, 0.29423558712005615, -0.15986312925815582, -0.14056296646595,
0.19754266738891602, -0.027508579194545746, -0.06699131429195404, 0.0232233926653862, -0.0022297834511846304, 0.034427981823682785, -0.024309569969773293, -0.02249000035226345,
0.02915329486131668, -0.0031451424583792686, -0.002920969156548381, -0.004697693977504969, -0.002039030659943819, 0.011053226888179779, -0.005162402521818876, -0.003320074640214443,
0.0025500659830868244, -3.137394475294655e-19, 0.0012425485765561461, -0.001634512678720057, -0.00033831183100119233, 0.0011541674612089992, -0.00033252930734306574, -9.587364183971658e-05,
-5.399842848419212e-05, 2.393690010649152e-05, 8.409668953390792e-05, -4.4569740566657856e-05, -3.264233100708225e-06, 3.264233100708225e-06, 1.0457537428010255e-05, -5.619160947389901e-05,
0.00010201841359958053, -5.399842848419212e-05, -0.00016925214731600136, 0.0004976652562618256, -0.0006537833833135664, 0.00033831183100119233, 0.00038351083640009165, -0.0008302443893626332,
-1.3371489373229684e-18, 0.0025500659830868244, -0.00586114963516593, 0.007726081181317568, -0.006261149886995554, 0.002039030659943819, 0.0011022347025573254, 0.001951729180291295,
-0.013404511846601963, 0.02915329486131668, -0.03970310091972351, 0.03638184070587158, -0.019501883536577225, 0.0022297834511846304, -0.005448977462947369, 0.04476216807961464,
-0.11724080890417099, 0.19754266738891602, -0.248145192861557, 0.23925207555294037, -0.16667106747627258, 0.05613646283745766, 0.049359146505594254, -0.11189892888069153,
0.11724080890417099, -0.0790216475725174, 0.02739386074244976, 0.009503276087343693, -0.019501883536577225, 0.008536385372281075, 0.007897437550127506, -0.016514014452695847,
0.013404511846601963, -0.003445517970249057, -0.0055413078516721725, 0.008690292946994305, -0.006261149886995554, 0.0018127945950254798, 0.001165855210274458, -0.0014444963308051229,
1.3371489373229684e-18, 0.001465685898438096, -0.0019280391279608011, 0.0014418758219107985, -0.0006537833833135664, 0.000116768766019959, 3.366634700796567e-05, 3.05876528727822e-05,
-0.00010201841359958053, 9.919880540110171e-05, -5.2573592256521806e-05, 1.391207206324907e-05
};
#endif // NET_IMPL_H