You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/01/23 00:50:53 UTC

[GitHub] ThomasDelteil commented on a change in pull request #13735: update wavenet codes

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

 ##########
 File path: example/gluon/wavenet/trainer.py
 ##########
 @@ -0,0 +1,130 @@
+# 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 trainer modulep
+"""
+import sys
+import numpy as np
+import mxnet as mx
+from mxnet import gluon, autograd, nd
+from tqdm import trange
+
+from models import WaveNet
+from utils import decode_mu_law
+from data_loader import load_wav, data_generation, data_generation_sample
+# pylint: disable=invalid-name, too-many-arguments, too-many-instance-attributes, no-member, no-self-use
+# set gpu count
+def setting_ctx(use_gpu):
+    """
+    Description : setting cpu/gpu
+    """
+    if eval(use_gpu):
+        ctx = mx.gpu()
+    else:
+        ctx = mx.cpu()
+    return ctx
+
+class Train():
+    """
+    Description : Trainer for WaveNet
+    """
+    def __init__(self, config):
+        ##setting hyper-parameters
+        self.batch_size = config.batch_size
+        self.epoches = config.epoches
+        self.mu = config.mu
+        self.n_residue = config.n_residue
+        self.n_skip = config.n_skip
+        self.dilation_depth = config.dilation_depth
+        self.n_repeat = config.n_repeat
+        self.seq_size = config.seq_size
+        self.use_gpu = config.use_gpu
+        self.ctx = setting_ctx(self.use_gpu)
+        self.build_model()
+
+    def build_model(self):
+        """
+        Description : module for building network
+        """
+        self.net = WaveNet(mu=self.mu, n_residue=self.n_residue, n_skip=self.n_skip,\
+         dilation_depth=self.dilation_depth, n_repeat=self.n_repeat)
+        #parameter initialization
+        self.net.collect_params().initialize(ctx=self.ctx)
+        #set optimizer
+        self.trainer = gluon.Trainer(self.net.collect_params(), optimizer='adam',\
+        optimizer_params={'learning_rate':0.01})
+        self.loss_fn = gluon.loss.SoftmaxCrossEntropyLoss()
+
+    def save_model(self, epoch, current_loss):
+        """
+        Description : module for saving network
+        """
+        filename = 'models/best_perf_epoch_'+str(epoch)+"_loss_"+str(current_loss)
+        self.net.save_params(filename)
+
+    def train(self):
+        """
+        Description : module for running train
+        """
+        fs, data = load_wav('parametric-2.wav')
 
 Review comment:
   why is this wavefile hardcoded?

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


With regards,
Apache Git Services