soeque1 commented on a change in pull request #13647: Update lip reading example
URL: https://github.com/apache/incubator-mxnet/pull/13647#discussion_r250219420
 
 

 ##########
 File path: example/gluon/lipnet/trainer.py
 ##########
 @@ -0,0 +1,152 @@
+# 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.
+
+"""
+Description : Training module for LipNet
+"""
+
+
+import sys
+import mxnet as mx
+from mxnet import gluon, autograd, nd
+from mxnet.gluon.data.vision import transforms
+from tqdm import tqdm, trange
+from data_loader import LipsDataset
+from models.network import LipNet
+from BeamSearch import ctcBeamSearch
+from utils.common import char_conv, int2char
+# set gpu count
+
+
+def setting_ctx(num_gpus):
+    """
+    Description : set gpu module
+    """
+    if num_gpus > 0:
+        ctx = [mx.gpu(i) for i in range(num_gpus)]
+    else:
+        ctx = [mx.cpu()]
+    return ctx
+
+
+ALPHABET = ''
+for i in range(27):
+    ALPHABET += int2char(i)
+
+def char_beam_search(out):
+    """
+    Description : apply beam search for prediction result
+    """
+    out_conv = list()
+    for idx in range(out.shape[0]):
+        probs = out[idx]
+        prob = probs.softmax().asnumpy()
+        line_string_proposals = ctcBeamSearch(prob, ALPHABET, None, k=4, 
beamWidth=25)
+        out_conv.append(line_string_proposals[0])
+    return out_conv
+
+# pylint: disable=too-many-instance-attributes, too-many-locals
+class Train:
+    """
+    Description : Train class for training network
+    """
+    def __init__(self, config):
+        ##setting hyper-parameters
+        self.batch_size = config.batch_size
+        self.epochs = config.epochs
+        self.image_path = config.image_path
+        self.align_path = config.align_path
+        self.dr_rate = config.dr_rate
+        self.num_gpus = config.num_gpus
+        self.ctx = setting_ctx(self.num_gpus)
+        self.num_workers = config.num_workers
+        self.build_model()
+
+    def build_model(self):
+        """
+        Description : build network
+        """
+        #set network
+        self.net = LipNet(self.dr_rate)
+        self.net.initialize(ctx=self.ctx)
+        #set optimizer
+        self.loss_fn = gluon.loss.CTCLoss()
+        self.trainer = gluon.Trainer(self.net.collect_params(), \
+                                     optimizer='SGD')
+    def save_model(self, epoch, iter_no, current_loss):
 
 Review comment:
   Fixed

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to