class WaveNet(chainer.Chain): def __init__(self, n_loop, n_layer, a_channels, r_channels, s_channels, use_embed_tanh): super(WaveNet, self).__init__() with self.init_scope(): self.embed = L.Convolution2D(a_channels, r_channels, (2, 1), pad=(1, 0), nobias=True) self.resnet = ResidualNet(n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = L.Convolution2D(s_channels, s_channels, 1, nobias=True) self.proj2 = L.Convolution2D(s_channels, a_channels, 1, nobias=True) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh def __call__(self, x, condition, generating=False): length = x.shape[2] x = self.embed(x) x = x[:, :, :length, :] # crop if self.use_embed_tanh: x = F.tanh(x) z = F.relu(self.resnet(x, condition)) z = F.relu(self.proj1(z)) y = self.proj2(z) return y def initialize(self, n): self.resnet.initialize(n) self.embed.pad = (0, 0) self.embed_queue = chainer.Variable( self.xp.zeros((n, self.a_channels, 2, 1), dtype=self.xp.float32)) self.proj1_queue = chainer.Variable( self.xp.zeros((n, self.s_channels, 1, 1), dtype=self.xp.float32)) self.proj2_queue3 = chainer.Variable( self.xp.zeros((n, self.s_channels, 1, 1), dtype=self.xp.float32)) def generate(self, x, condition): self.embed_queue = F.concat((self.embed_queue[:, :, 1:], x), axis=2) x = self.embed(self.embed_queue) if self.use_embed_tanh: x = F.tanh(x) x = F.relu(self.resnet.generate(x, condition)) self.proj1_queue = F.concat((self.proj1_queue[:, :, 1:], x), axis=2) x = F.relu(self.proj1(self.proj1_queue)) self.proj2_queue3 = F.concat((self.proj2_queue3[:, :, 1:], x), axis=2) x = self.proj2(self.proj2_queue3) return x
class WaveNet(nn.Module): def __init__(self, n_loop=4, n_layer=10, a_channels=256, r_channels=64, s_channels=256, use_embed_tanh=True): super().__init__() self.embed = nn.Conv1d(a_channels, r_channels, 2, padding=1, bias=False) self.resnet = ResidualNet(n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = nn.Conv1d(s_channels, s_channels, 1, bias=False) self.proj2 = nn.Conv1d(s_channels, a_channels, 1, bias=False) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh def forward(self, x, condition): length = x.size(2) x = self.embed(x) x = x[:, :, :length] # crop if self.use_embed_tanh: x = torch.tanh(x) z = F.relu(self.resnet(x, condition)) z = F.relu(self.proj1(z)) y = self.proj2(z) return y def initialize(self, n): self.resnet.initialize(n) self.embed.padding = 0 self.embed_queue = torch.zeros((n, self.a_channels, 2), dtype=self.embed.weight.dtype) self.proj1_queue = torch.zeros((n, self.s_channels, 1), dtype=self.proj1.weight.dtype) self.proj2_queue = torch.zeros((n, self.s_channels, 1), dtype=self.proj2.weight.dtype) def generate(self, x, condition): self.embed_queue = torch.cat((self.embed_queue[:, :, 1:], x), dim=2) x = self.embed(self.embed_queue) if self.use_embed_tanh: x = torch.tanh(x) x = F.relu(self.resnet.generate(x, condition)) self.proj1_queue = torch.cat((self.proj1_queue[:, :, 1:], x), dim=2) x = F.relu(self.proj1(self.proj1_queue)) self.proj2_queue = torch.cat((self.proj2_queue[:, :, 1:], x), dim=2) x = self.proj2(self.proj2_queue) return x
class WaveNet(chainer.Chain): def __init__(self, n_loop, n_layer, a_channels, r_channels, s_channels, use_embed_tanh): super(WaveNet, self).__init__() with self.init_scope(): self.embed = L.Convolution2D( a_channels, r_channels, (2, 1), pad=(1, 0), nobias=True) self.resnet = ResidualNet( n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = L.Convolution2D( s_channels, s_channels, 1, nobias=True) self.proj2 = L.Convolution2D( s_channels, a_channels, 1, nobias=True) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh def __call__(self, x, condition, generating=False): length = x.shape[2] x = self.embed(x) x = x[:, :, :length, :] # crop if self.use_embed_tanh: x = F.tanh(x) z = F.relu(self.resnet(x, condition)) z = F.relu(self.proj1(z)) y = self.proj2(z) return y def initialize(self, n): self.resnet.initialize(n) self.embed.pad = (0, 0) self.embed_queue = chainer.Variable(self.xp.zeros( (n, self.a_channels, 2, 1), dtype=self.embed.W.dtype)) self.proj1_queue = chainer.Variable(self.xp.zeros( (n, self.s_channels, 1, 1), dtype=self.proj1.W.dtype)) self.proj2_queue3 = chainer.Variable(self.xp.zeros( (n, self.s_channels, 1, 1), dtype=self.proj2.W.dtype)) def generate(self, x, condition): self.embed_queue = F.concat((self.embed_queue[:, :, 1:], x), axis=2) x = self.embed(self.embed_queue) if self.use_embed_tanh: x = F.tanh(x) x = F.relu(self.resnet.generate(x, condition)) self.proj1_queue = F.concat((self.proj1_queue[:, :, 1:], x), axis=2) x = F.relu(self.proj1(self.proj1_queue)) self.proj2_queue3 = F.concat((self.proj2_queue3[:, :, 1:], x), axis=2) x = self.proj2(self.proj2_queue3) return x
def __init__(self, n_loop=4, n_layer=10, a_channels=256, r_channels=64, s_channels=256, use_embed_tanh=True): super().__init__() self.embed = nn.Conv1d(a_channels, r_channels, 2, padding=1, bias=False) self.resnet = ResidualNet(n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = nn.Conv1d(s_channels, s_channels, 1, bias=False) self.proj2 = nn.Conv1d(s_channels, a_channels, 1, bias=False) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh
def __init__(self, n_loop, n_layer, a_channels, r_channels, s_channels, use_embed_tanh): super(WaveNet, self).__init__() with self.init_scope(): self.embed = L.Convolution2D(a_channels, r_channels, (2, 1), pad=(1, 0), nobias=True) self.resnet = ResidualNet(n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = L.Convolution2D(s_channels, s_channels, 1, nobias=True) self.proj2 = L.Convolution2D(s_channels, a_channels, 1, nobias=True) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh
def __init__(self, n_loop, n_layer, a_channels, r_channels, s_channels, use_embed_tanh): super(WaveNet, self).__init__() with self.init_scope(): self.embed = L.Convolution2D( a_channels, r_channels, (2, 1), pad=(1, 0), nobias=True) self.resnet = ResidualNet( n_loop, n_layer, 2, r_channels, 2 * r_channels, s_channels) self.proj1 = L.Convolution2D( s_channels, s_channels, 1, nobias=True) self.proj2 = L.Convolution2D( s_channels, a_channels, 1, nobias=True) self.a_channels = a_channels self.s_channels = s_channels self.use_embed_tanh = use_embed_tanh