seujung commented on a change in pull request #13735: update wavenet codes
URL: https://github.com/apache/incubator-mxnet/pull/13735#discussion_r291452520
 
 

 ##########
 File path: example/gluon/wavenet/models.py
 ##########
 @@ -0,0 +1,118 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Module: WaveNet network block
+"""
+from mxnet import nd
+from mxnet.gluon import nn
+# pylint: disable=invalid-name, too-many-arguments, arguments-differ, 
attribute-defined-outside-init, too-many-instance-attributes, 
invalid-sequence-index, no-self-use
+
+class WaveNet(nn.HybridBlock):
+    """
+    mu: audio quantization size
+    n_residue: residue channels
+    n_skip: skip channels
+    dilation_depth : set the dilation depth for dilation layer
+    n_repeat: set number of repeat for dilation layer
+    """
+    def __init__(self, input_length, mu=256, n_residue=32, n_skip=512, 
dilation_depth=10, n_repeat=5):
+        super(WaveNet, self).__init__()
+        self.mu = mu
+        self.input_length = input_length
+        self.dilation_depth = dilation_depth
+        self.dilations = [2**i for i in range(dilation_depth)] * n_repeat
+        with self.name_scope():
+            self.from_input = nn.Conv1D(in_channels=mu, channels=n_residue, 
kernel_size=1)
+            self.conv_sigmoid = nn.HybridSequential()
+            self.conv_tanh = nn.HybridSequential()
+            self.skip_scale = nn.HybridSequential()
+            self.residue_scale = nn.HybridSequential()
+            for d in self.dilations:
+                self.conv_sigmoid.add(nn.Conv1D(in_channels=n_residue,\
+                 channels=n_residue, kernel_size=2, dilation=d))
+                self.conv_tanh.add(nn.Conv1D(in_channels=n_residue,\
+                 channels=n_residue, kernel_size=2, dilation=d))
+                self.skip_scale.add(nn.Conv1D(in_channels=n_residue,\
+                 channels=n_skip, kernel_size=1, dilation=d))
+                self.residue_scale.add(nn.Conv1D(in_channels=n_residue,\
+                 channels=n_residue, kernel_size=1, dilation=d))
+            self.conv_post_1 = nn.Conv1D(in_channels=n_skip, channels=n_skip, 
kernel_size=1)
+            self.conv_post_2 = nn.Conv1D(in_channels=n_skip, channels=mu, 
kernel_size=1)
+
+    def hybrid_forward(self, F, x):
+        output = self.preprocess(x)
+        skip_connections = [] # save for generation purposes
+        idx = 1
+        for s, t, skip_scale, residue_scale in zip(self.conv_sigmoid, 
self.conv_tanh, self.skip_scale, self.residue_scale):
+            output, skip = self.residue_forward(F, output, s, t, skip_scale, 
residue_scale, idx)
+            skip_connections.append(skip)
+            idx = idx + 1
+        # sum up skip connections
+        # previous code : output = sum([s[:,:,-output.shape[2]:] for s in 
skip_connections])
+        output_length = self.calc_output_size(idx)
+        output = sum([F.slice_axis(s, axis=2, begin=0, end=output_length) for 
s in skip_connections])
+        output = self.postprocess(F, output)
+        return output
+
+    def preprocess(self, x):
+        """
+        Description : module for preprocess
+        """
+        output = self.from_input(x)
+        return output
 
 Review comment:
   fix code 
https://github.com/apache/incubator-mxnet/pull/13735/commits/32a3b6eb2b53f27a5bddbfd130ac2e357877475d

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to