예제 #1
0
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
예제 #2
0
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
예제 #3
0
파일: net.py 프로젝트: asi1024/chainer
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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
파일: net.py 프로젝트: asi1024/chainer
 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