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

jxie 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 dc3ea81  [MXNET-313] Python: Resolve some of the undefined names 
(#10490)
dc3ea81 is described below

commit dc3ea8161dab81b9b49daffcc09d36d8898e017b
Author: cclauss <ccla...@bluewin.ch>
AuthorDate: Mon Apr 23 21:35:13 2018 +0200

    [MXNET-313] Python: Resolve some of the undefined names (#10490)
---
 example/bi-lstm-sort/lstm_sort.py                  | 12 +++++----
 .../data_helpers.py                                |  9 ++++---
 example/cnn_text_classification/data_helpers.py    | 10 +++++---
 example/fcn-xs/solver.py                           |  2 +-
 example/gluon/style_transfer/utils.py              |  4 ++-
 example/gluon/tree_lstm/dataset.py                 | 16 +++++++-----
 example/reinforcement-learning/a3c/rl_data.py      | 30 +++++++++++-----------
 python/mxnet/gluon/parameter.py                    |  3 +--
 python/mxnet/optimizer.py                          |  1 +
 9 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/example/bi-lstm-sort/lstm_sort.py 
b/example/bi-lstm-sort/lstm_sort.py
index 3fd4a2a..3d7090a 100644
--- a/example/bi-lstm-sort/lstm_sort.py
+++ b/example/bi-lstm-sort/lstm_sort.py
@@ -17,27 +17,29 @@
 
 # pylint: 
disable=C0111,too-many-arguments,too-many-instance-attributes,too-many-locals,redefined-outer-name,fixme
 # pylint: disable=superfluous-parens, no-member, invalid-name
+import argparse
+import errno
+import logging
 import os
+import random
 import sys
+
 import numpy as np
-import mxnet as mx
-import random
-import argparse
 
+import mxnet as mx
 from lstm import bi_lstm_unroll
 from sort_io import BucketSentenceIter, default_build_vocab
 
-import logging
 head = '%(asctime)-15s %(message)s'
 logging.basicConfig(level=logging.DEBUG, format=head)
 
-
 TRAIN_FILE = "sort.train.txt"
 TEST_FILE = "sort.test.txt"
 VALID_FILE = "sort.valid.txt"
 DATA_DIR = os.path.join(os.getcwd(), "data")
 SEQ_LEN = 5
 
+
 def gen_data(seq_len, start_range, end_range):
     if not os.path.exists(DATA_DIR):
         try:
diff --git a/example/cnn_chinese_text_classification/data_helpers.py 
b/example/cnn_chinese_text_classification/data_helpers.py
index 1a5c4ad..b3a13de 100644
--- a/example/cnn_chinese_text_classification/data_helpers.py
+++ b/example/cnn_chinese_text_classification/data_helpers.py
@@ -15,16 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 import codecs
-
-import numpy as np
-import re
 import itertools
-from collections import Counter
 import os
+import re
+from collections import Counter
 
+import numpy as np
 
+import word2vec
 # from gensim.models import word2vec
 
+
 def clean_str(string):
     """
     Tokenization/string cleaning for all datasets except for SST.
diff --git a/example/cnn_text_classification/data_helpers.py 
b/example/cnn_text_classification/data_helpers.py
index 3812683..b6fe1e6 100644
--- a/example/cnn_text_classification/data_helpers.py
+++ b/example/cnn_text_classification/data_helpers.py
@@ -15,13 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import numpy as np
-import re
 import itertools
-from collections import Counter
 import os
+import re
+from collections import Counter
+
+import numpy as np
+
+import word2vec
 # from gensim.models import word2vec
 
+
 def clean_str(string):
     """
     Tokenization/string cleaning for all datasets except for SST.
diff --git a/example/fcn-xs/solver.py b/example/fcn-xs/solver.py
index cf7298b..e99b31a 100644
--- a/example/fcn-xs/solver.py
+++ b/example/fcn-xs/solver.py
@@ -63,7 +63,7 @@ class Solver(object):
         else:
             self.grad_params = None
         aux_names = self.symbol.list_auxiliary_states()
-        self.aux_params = {k : nd.zeros(s) for k, s in zip(aux_names, 
aux_shapes)}
+        self.aux_params = {k: mx.nd.zeros(s) for k, s in zip(aux_names, 
aux_shapes)}
         data_name = train_data.data_name
         label_name = train_data.label_name
         input_names = [data_name, label_name]
diff --git a/example/gluon/style_transfer/utils.py 
b/example/gluon/style_transfer/utils.py
index e027331..f869512 100644
--- a/example/gluon/style_transfer/utils.py
+++ b/example/gluon/style_transfer/utils.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import collections
 import os
 import numbers
 from PIL import Image
@@ -23,6 +24,7 @@ import numpy as np
 import mxnet as mx
 import mxnet.ndarray as F
 
+
 def tensor_load_rgbimage(filename, ctx, size=None, scale=None, keep_asp=False):
     img = Image.open(filename).convert('RGB')
     if size is not None:
@@ -209,7 +211,7 @@ class StyleLoader():
         self.files = os.listdir(style_folder)
         assert(len(self.files) > 0)
         self.ctx = ctx
-    
+
     def get(self, i):
         idx = i%len(self.files)
         filepath = os.path.join(self.folder, self.files[idx])
diff --git a/example/gluon/tree_lstm/dataset.py 
b/example/gluon/tree_lstm/dataset.py
index 4a836dd..02c57c0 100644
--- a/example/gluon/tree_lstm/dataset.py
+++ b/example/gluon/tree_lstm/dataset.py
@@ -15,14 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import os
 import logging
-logging.basicConfig(level=logging.INFO)
-import numpy as np
+import os
 import random
-from tqdm import tqdm
+
+import numpy as np
 
 import mxnet as mx
+from tqdm import tqdm
+
+logging.basicConfig(level=logging.INFO)
+
 
 class Vocab(object):
     # constants for special tokens: padding, unknown, and beginning/end of 
sentence.
@@ -34,6 +37,7 @@ class Vocab(object):
     UNK_WORD = '<unk>'
     BOS_WORD = '<s>'
     EOS_WORD = '</s>'
+
     def __init__(self, filepaths=[], embedpath=None, include_unseen=False, 
lower=False):
         self.idx2tok = []
         self.tok2idx = {}
@@ -82,10 +86,10 @@ class Vocab(object):
         return idx
 
     def to_indices(self, tokens, add_bos=False, add_eos=False):
-        vec = [BOS] if add_bos else []
+        vec = [Vocab.BOS] if add_bos else []
         vec += [self.get_index(token) for token in tokens]
         if add_eos:
-            vec.append(EOS)
+            vec.append(Vocab.EOS)
         return vec
 
     def to_tokens(self, indices, stop):
diff --git a/example/reinforcement-learning/a3c/rl_data.py 
b/example/reinforcement-learning/a3c/rl_data.py
index 70f2853..28ebec4 100644
--- a/example/reinforcement-learning/a3c/rl_data.py
+++ b/example/reinforcement-learning/a3c/rl_data.py
@@ -16,24 +16,26 @@
 # under the License.
 
 from __future__ import print_function
-import mxnet as mx
-import numpy as np
-import gym
-import cv2
+
 import math
-from threading import Thread
-import time
 import multiprocessing
 import multiprocessing.pool
-from flask import Flask, render_template, Response
-import signal
-import sys
-is_py3 = sys.version[0] == '3'
-if is_py3:
+import time
+from threading import Thread
+
+import numpy as np
+from flask import Flask, Response, render_template
+
+import cv2
+import gym
+import mxnet as mx
+
+try:
     import queue as queue
-else:
+except ImportError:
     import Queue as queue
 
+
 def make_web(queue):
     app = Flask(__name__)
 
@@ -136,7 +138,7 @@ class RLDataIter(object):
             try:
                 while self.queue.qsize() > 10:
                     self.queue.get(False)
-            except Empty:
+            except queue.Empty:
                 pass
             frame = self.visual()
             self.queue.put(frame)
@@ -173,5 +175,3 @@ if __name__ == '__main__':
             dataiter.next()
         print(batch_size*100/(time.time() - tic))
         tic = time.time()
-
-
diff --git a/python/mxnet/gluon/parameter.py b/python/mxnet/gluon/parameter.py
index 99885eb..04694df 100644
--- a/python/mxnet/gluon/parameter.py
+++ b/python/mxnet/gluon/parameter.py
@@ -26,7 +26,6 @@ from collections import OrderedDict
 import warnings
 import numpy as np
 
-
 from ..base import mx_real_t, MXNetError
 from .. import symbol, ndarray, initializer, context
 from ..context import Context, cpu
@@ -645,7 +644,7 @@ class ParameterDict(object):
             assert isinstance(param, Constant), \
                 "Parameter '{}' already exists but it is not a 
constant.".format(
                     name)
-            if isinstance(value, nd.NDArray):
+            if isinstance(value, ndarray.NDArray):
                 value = value.asnumpy()
             assert param.shape == value.shape and \
                 (param.value.asnumpy() == value).all(), \
diff --git a/python/mxnet/optimizer.py b/python/mxnet/optimizer.py
index 2f7c51b..65540a9 100644
--- a/python/mxnet/optimizer.py
+++ b/python/mxnet/optimizer.py
@@ -18,6 +18,7 @@
 # coding: utf-8
 # pylint: disable=too-many-lines
 """Weight updating functions."""
+import logging
 import math
 import pickle
 import warnings

-- 
To stop receiving notification emails like this one, please contact
j...@apache.org.

Reply via email to