indhub closed pull request #12951: Update Gluon example folder
URL: https://github.com/apache/incubator-mxnet/pull/12951
 
 
   

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/docs/tutorials/unsupervised_learning/gan.md 
b/docs/tutorials/unsupervised_learning/gan.md
index 1556bf609aa..f436a15bac5 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 be1ffc29024..00000000000
--- 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 3e95c054fed..9c221857731 100644
--- a/example/gluon/lstm_crf.py
+++ b/example/gluon/lstm_crf/lstm_crf.py
@@ -21,8 +21,8 @@
 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 @@ def forward(self, sentence):  # dont confuse this with 
_forward_alg above.
 
 # 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 @@ def forward(self, sentence):  # dont confuse this with 
_forward_alg above.
             # 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 7ed4c38a3b3..782f74ffca5 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 b714c758788..6040adb4eea 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 f4b9884810c..5faf3a2a02a 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 06c02300bc3..1a77a6e90ec 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 27ff7fabbe6..00000000000
--- 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.


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to