You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by in...@apache.org on 2018/11/06 19:02:03 UTC

[incubator-mxnet] branch master updated: Update Gluon example folder (#12951)

This is an automated email from the ASF dual-hosted git repository.

indhub pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new c169b14  Update Gluon example folder (#12951)
c169b14 is described below

commit c169b14b35cb8eb25df166d2e5f5ddc1c4fa5d5f
Author: Thomas Delteil <th...@gmail.com>
AuthorDate: Tue Nov 6 11:01:43 2018 -0800

    Update Gluon example folder (#12951)
    
    * Reorganized the Gluon folder in example
    
    * trigger CI
    
    * update reference
    
    * fix out of place accumulation
---
 docs/tutorials/unsupervised_learning/gan.md        |  2 +-
 example/gluon/{ => actor_critic}/actor_critic.py   |  0
 example/gluon/{DCGAN => dc_gan}/README.md          |  0
 example/gluon/{DCGAN => dc_gan}/__init__.py        |  0
 example/gluon/{DCGAN => dc_gan}/dcgan.py           |  0
 example/gluon/{DCGAN => dc_gan}/inception_score.py |  0
 .../kaggle_k_fold_cross_validation.py              |  0
 example/gluon/learning_rate_manipulation.py        | 63 ----------------------
 example/gluon/{ => lstm_crf}/lstm_crf.py           | 10 ++--
 example/gluon/{ => mnist}/mnist.py                 |  0
 example/gluon/sn_gan/data.py                       |  2 +-
 example/gluon/sn_gan/model.py                      |  2 +-
 example/gluon/sn_gan/train.py                      |  2 +-
 example/gluon/sn_gan/utils.py                      |  2 +-
 .../{ => super_resolution}/super_resolution.py     |  0
 example/notebooks/README.md                        |  4 --
 16 files changed, 12 insertions(+), 75 deletions(-)

diff --git a/docs/tutorials/unsupervised_learning/gan.md b/docs/tutorials/unsupervised_learning/gan.md
index 1556bf6..f436a15 100644
--- a/docs/tutorials/unsupervised_learning/gan.md
+++ b/docs/tutorials/unsupervised_learning/gan.md
@@ -394,7 +394,7 @@ As a result, we have created two neural nets: a Generator, which is able to crea
 Along the way, we have learned how to do the image manipulation and visualization that is associated with the training of deep neural nets. We have also learned how to use MXNet's Module APIs to perform advanced model training functionality to fit the model.
 
 ## Acknowledgements
-This tutorial is based on [MXNet DCGAN codebase](https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dcgan.py),
+This tutorial is based on [MXNet DCGAN codebase](https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dc_gan/dcgan.py),
 [The original paper on GANs](https://arxiv.org/abs/1406.2661), as well as [this paper on deep convolutional GANs](https://arxiv.org/abs/1511.06434).
 
 <!-- INSERT SOURCE DOWNLOAD BUTTONS -->
\ No newline at end of file
diff --git a/example/gluon/actor_critic.py b/example/gluon/actor_critic/actor_critic.py
similarity index 100%
rename from example/gluon/actor_critic.py
rename to example/gluon/actor_critic/actor_critic.py
diff --git a/example/gluon/DCGAN/README.md b/example/gluon/dc_gan/README.md
similarity index 100%
rename from example/gluon/DCGAN/README.md
rename to example/gluon/dc_gan/README.md
diff --git a/example/gluon/DCGAN/__init__.py b/example/gluon/dc_gan/__init__.py
similarity index 100%
rename from example/gluon/DCGAN/__init__.py
rename to example/gluon/dc_gan/__init__.py
diff --git a/example/gluon/DCGAN/dcgan.py b/example/gluon/dc_gan/dcgan.py
similarity index 100%
rename from example/gluon/DCGAN/dcgan.py
rename to example/gluon/dc_gan/dcgan.py
diff --git a/example/gluon/DCGAN/inception_score.py b/example/gluon/dc_gan/inception_score.py
similarity index 100%
rename from example/gluon/DCGAN/inception_score.py
rename to example/gluon/dc_gan/inception_score.py
diff --git a/example/gluon/kaggle_k_fold_cross_validation.py b/example/gluon/house_prices/kaggle_k_fold_cross_validation.py
similarity index 100%
rename from example/gluon/kaggle_k_fold_cross_validation.py
rename to example/gluon/house_prices/kaggle_k_fold_cross_validation.py
diff --git a/example/gluon/learning_rate_manipulation.py b/example/gluon/learning_rate_manipulation.py
deleted file mode 100644
index be1ffc2..0000000
--- a/example/gluon/learning_rate_manipulation.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# 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.
-
-
-# This example demonstrates how to manipulate the learning rate of an optimizer
-# in gluon. The example uses linear regression as a case study.
-
-from __future__ import print_function
-import numpy as np
-import mxnet as mx
-from mxnet import autograd
-from mxnet import gluon
-
-# Generate synthetic data.
-X = np.random.randn(10000, 2)
-Y = 2 * X[:, 0] - 3.4 * X[:, 1] + 4.2 + .01 * np.random.normal(size=10000)
-
-net = gluon.nn.Sequential()
-# The output dimension is 1.
-net.add(gluon.nn.Dense(1))
-net.initialize()
-loss = gluon.loss.L2Loss()
-
-# Initialize the learning rate as 0.1.
-trainer = gluon.Trainer(net.collect_params(), 'sgd',
-                        optimizer_params={'learning_rate': 0.1})
-net.initialize(mx.init.Xavier(magnitude=2.24),
-                                force_reinit=True)
-train_data = mx.io.NDArrayIter(X, Y, batch_size=10, shuffle=True)
-
-for epoch in range(5):
-    train_data.reset()
-    for i, batch in enumerate(train_data):
-        data = batch.data[0]
-        label = batch.label[0].reshape((-1, 1))
-        with autograd.record():
-            output = net(data)
-            mse = loss(output, label)
-        mse.backward()
-        trainer.step(data.shape[0])
-    # After the second epoch, decay the learning rate of the optimizer every
-    # epoch.
-    if epoch > 1:
-        trainer.set_learning_rate(trainer.learning_rate * 0.9)
-    print('Epoch:', epoch, 'Learning rate:', trainer.learning_rate)
-
-for para_name, para_value in net.collect_params().items():
-    # Print all the parameter values after training.
-    print(para_name, para_value.data().asnumpy()[0])
diff --git a/example/gluon/lstm_crf.py b/example/gluon/lstm_crf/lstm_crf.py
similarity index 95%
rename from example/gluon/lstm_crf.py
rename to example/gluon/lstm_crf/lstm_crf.py
index 3e95c05..9c22185 100644
--- a/example/gluon/lstm_crf.py
+++ b/example/gluon/lstm_crf/lstm_crf.py
@@ -21,8 +21,8 @@ from mxnet.gluon import Block, nn, rnn
 import mxnet.optimizer as optim
 import sys
 
-# This example demonstrates how LSTM-CRF model can be implemented in Gluon to perform
-# noun-phrase chunking as a sequence labeling task.
+# This example demonstrates how the LSTM-CRF model can be implemented 
+# in Gluon to perform noun-phrase chunking as a sequence labeling task.
 
 mx.random.seed(1)
 
@@ -208,7 +208,9 @@ print(model(precheck_sent))
 
 # Make sure prepare_sequence from earlier in the LSTM section is loaded
 for epoch in range(300):  # again, normally you would NOT do 300 epochs, it is toy data
-    for sentence, tags in training_data:
+
+    neg_log_likelihood_acc = 0.
+    for i, (sentence, tags) in enumerate(training_data):
         # Step 1. Get our inputs ready for the network, that is,
         # turn them into Variables of word indices.
         # Remember to use autograd to record the calculation.
@@ -223,6 +225,8 @@ for epoch in range(300):  # again, normally you would NOT do 300 epochs, it is t
             # calling optimizer.step()
             neg_log_likelihood.backward()
         optimizer.step(1)
+        neg_log_likelihood_acc += neg_log_likelihood.mean()
+    print("Epoch [{}], Negative Log Likelihood {:.4f}".format(epoch, neg_log_likelihood_acc.asscalar()/(i+1)))
 
 # Check predictions after training
 precheck_sent = prepare_sequence(training_data[0][0], word2idx)
diff --git a/example/gluon/mnist.py b/example/gluon/mnist/mnist.py
similarity index 100%
rename from example/gluon/mnist.py
rename to example/gluon/mnist/mnist.py
diff --git a/example/gluon/sn_gan/data.py b/example/gluon/sn_gan/data.py
index 7ed4c38..782f74f 100644
--- a/example/gluon/sn_gan/data.py
+++ b/example/gluon/sn_gan/data.py
@@ -17,7 +17,7 @@
 
 # This example is inspired by https://github.com/jason71995/Keras-GAN-Library,
 # https://github.com/kazizzad/DCGAN-Gluon-MxNet/blob/master/MxnetDCGAN.ipynb
-# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/DCGAN/dcgan.py
+# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dc_gan/dcgan.py
 
 import numpy as np
 
diff --git a/example/gluon/sn_gan/model.py b/example/gluon/sn_gan/model.py
index b714c75..6040adb 100644
--- a/example/gluon/sn_gan/model.py
+++ b/example/gluon/sn_gan/model.py
@@ -17,7 +17,7 @@
 
 # This example is inspired by https://github.com/jason71995/Keras-GAN-Library,
 # https://github.com/kazizzad/DCGAN-Gluon-MxNet/blob/master/MxnetDCGAN.ipynb
-# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/DCGAN/dcgan.py
+# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dc_gan/dcgan.py
 
 import mxnet as mx
 from mxnet import nd
diff --git a/example/gluon/sn_gan/train.py b/example/gluon/sn_gan/train.py
index f4b9884..5faf3a2 100644
--- a/example/gluon/sn_gan/train.py
+++ b/example/gluon/sn_gan/train.py
@@ -17,7 +17,7 @@
 
 # This example is inspired by https://github.com/jason71995/Keras-GAN-Library,
 # https://github.com/kazizzad/DCGAN-Gluon-MxNet/blob/master/MxnetDCGAN.ipynb
-# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/DCGAN/dcgan.py
+# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dc_gan/dcgan.py
 
 
 import os
diff --git a/example/gluon/sn_gan/utils.py b/example/gluon/sn_gan/utils.py
index 06c0230..1a77a6e 100644
--- a/example/gluon/sn_gan/utils.py
+++ b/example/gluon/sn_gan/utils.py
@@ -17,7 +17,7 @@
 
 # This example is inspired by https://github.com/jason71995/Keras-GAN-Library,
 # https://github.com/kazizzad/DCGAN-Gluon-MxNet/blob/master/MxnetDCGAN.ipynb
-# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/DCGAN/dcgan.py
+# https://github.com/apache/incubator-mxnet/blob/master/example/gluon/dc_gan/dcgan.py
 
 import math
 
diff --git a/example/gluon/super_resolution.py b/example/gluon/super_resolution/super_resolution.py
similarity index 100%
rename from example/gluon/super_resolution.py
rename to example/gluon/super_resolution/super_resolution.py
diff --git a/example/notebooks/README.md b/example/notebooks/README.md
deleted file mode 100644
index 27ff7fa..0000000
--- a/example/notebooks/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-Moved to
-https://github.com/dmlc/mxnet-notebooks/tree/master/python/moved-from-mxnet/
-
-This folder will be removed soon.