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 2017/12/08 19:26:22 UTC

[GitHub] piiswrong closed pull request #8987: Fix multi task

piiswrong closed pull request #8987: Fix multi task
URL: https://github.com/apache/incubator-mxnet/pull/8987
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/example/multi-task/README.md b/example/multi-task/README.md
index 698d6f468e..9034814c3b 100644
--- a/example/multi-task/README.md
+++ b/example/multi-task/README.md
@@ -5,4 +5,6 @@ This is a simple example to show how to use mxnet for multi-task learning. It us
 ## Usage
 First, you need to write a multi-task iterator on your own. The iterator needs to generate multiple labels according to your applications, and the label names should be specified in the `provide_label` function, which needs to be consist with the names of output layers. 
 
-Then, if you want to show metrics of different tasks separately, you need to write your own metric class and specify the `num` parameter. In the `update` function of metric, calculate the metrics separately for different tasks. 
+Then, if you want to show metrics of different tasks separately, you need to write your own metric class and specify the `num` parameter. In the `update` function of metric, calculate the metrics separately for different tasks.
+
+The example script uses gpu as device by default, if gpu is not available for your environment, you can change `device` to be `mx.cpu()`.
diff --git a/example/multi-task/example_multi_task.py b/example/multi-task/example_multi_task.py
index ec5ece985c..9ea9ad0173 100644
--- a/example/multi-task/example_multi_task.py
+++ b/example/multi-task/example_multi_task.py
@@ -18,7 +18,6 @@
 # pylint: skip-file
 import sys
 import os
-sys.path.insert(0, "../../python/")
 curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
 sys.path.append(os.path.join(curr_path, "../../tests/python/common"))
 from get_data import MNISTIterator
@@ -148,18 +147,17 @@ def get_name_value(self):
 val = Multi_mnist_iterator(val)
 
 
-model = mx.model.FeedForward(
-    ctx                = device,
+model = mx.mod.Module(
+    context            = device,
     symbol             = network,
-    num_epoch          = num_epochs,
-    learning_rate      = lr,
-    momentum           = 0.9,
-    wd                 = 0.00001,
-    initializer        = mx.init.Xavier(factor_type="in", magnitude=2.34))
+    label_names        = ('softmax1_label', 'softmax2_label'))
 
 model.fit(
-    X                  = train,
+    train_data         = train,
     eval_data          = val,
     eval_metric        = Multi_Accuracy(num=2),
+    num_epoch          = num_epochs,
+    optimizer_params   = (('learning_rate', lr), ('momentum', 0.9), ('wd', 0.00001)),
+    initializer        = mx.init.Xavier(factor_type="in", magnitude=2.34),
     batch_end_callback = mx.callback.Speedometer(batch_size, 50))
 


 

----------------------------------------------------------------
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