You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2018/07/16 21:36:14 UTC
[incubator-mxnet] branch master updated: Some Python 3 fixes in
./example (#11671)
This is an automated email from the ASF dual-hosted git repository.
zhreshold 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 bcf4245 Some Python 3 fixes in ./example (#11671)
bcf4245 is described below
commit bcf4245056d2a3961280a0a072eb4ef92e8f2fc5
Author: cclauss <cc...@bluewin.ch>
AuthorDate: Mon Jul 16 23:36:02 2018 +0200
Some Python 3 fixes in ./example (#11671)
* Some Python 3 fixes in ./example
* mxnet.base.string_types and xrange() --> range()
---
example/gluon/data.py | 7 ++++---
example/kaggle-ndsb1/gen_img_list.py | 5 +----
example/reinforcement-learning/ddpg/ddpg.py | 4 ++--
example/ssd/dataset/pycocotools/coco.py | 12 ++++++------
4 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/example/gluon/data.py b/example/gluon/data.py
index 5a7f9e6..6aa5316 100644
--- a/example/gluon/data.py
+++ b/example/gluon/data.py
@@ -19,6 +19,7 @@
""" data iterator for mnist """
import os
import random
+import tarfile
import logging
logging.basicConfig(level=logging.INFO)
@@ -111,7 +112,7 @@ def get_caltech101_iterator(batch_size, num_workers, dtype):
# center and crop an area of size (224,224)
cropped, crop_info = mx.image.center_crop(resized, 224)
# transpose the channels to be (3,224,224)
- transposed = nd.transpose(cropped, (2, 0, 1))
+ transposed = mx.nd.transpose(cropped, (2, 0, 1))
image = mx.nd.cast(image, dtype)
return image, label
@@ -119,8 +120,8 @@ def get_caltech101_iterator(batch_size, num_workers, dtype):
dataset_train = ImageFolderDataset(root=training_path, transform=transform)
dataset_test = ImageFolderDataset(root=testing_path, transform=transform)
- train_data = gluon.data.DataLoader(dataset_train, batch_size, shuffle=True, num_workers=num_workers)
- test_data = gluon.data.DataLoader(dataset_test, batch_size, shuffle=False, num_workers=num_workers)
+ train_data = mx.gluon.data.DataLoader(dataset_train, batch_size, shuffle=True, num_workers=num_workers)
+ test_data = mx.gluon.data.DataLoader(dataset_test, batch_size, shuffle=False, num_workers=num_workers)
return DataLoaderIter(train_data), DataLoaderIter(test_data)
class DummyIter(mx.io.DataIter):
diff --git a/example/kaggle-ndsb1/gen_img_list.py b/example/kaggle-ndsb1/gen_img_list.py
index adfc4fe..8b27550 100644
--- a/example/kaggle-ndsb1/gen_img_list.py
+++ b/example/kaggle-ndsb1/gen_img_list.py
@@ -18,7 +18,6 @@
from __future__ import print_function
import csv
import os
-import sys
import random
import numpy as np
import argparse
@@ -57,7 +56,7 @@ head = "acantharia_protist_big_center,acantharia_protist_halo,acantharia_protist
img_lst = []
cnt = 0
if args.train:
- for i in xrange(len(head)):
+ for i in range(len(head)):
path = args.image_folder + head[i]
lst = os.listdir(args.image_folder + head[i])
for img in lst:
@@ -104,5 +103,3 @@ if args.train:
tr_fo.writerow(item)
for item in va_lst:
va_fo.writerow(item)
-
-
diff --git a/example/reinforcement-learning/ddpg/ddpg.py b/example/reinforcement-learning/ddpg/ddpg.py
index aa34e4d..14c1795 100644
--- a/example/reinforcement-learning/ddpg/ddpg.py
+++ b/example/reinforcement-learning/ddpg/ddpg.py
@@ -190,7 +190,7 @@ class DDPG(object):
end = False
obs = self.env.reset()
- for epoch in xrange(self.n_epochs):
+ for epoch in range(self.n_epochs):
logger.push_prefix("epoch #%d | " % epoch)
logger.log("Training started")
for epoch_itr in pyprind.prog_bar(range(self.epoch_length)):
@@ -220,7 +220,7 @@ class DDPG(object):
obs = nxt
if memory.size >= self.memory_start_size:
- for update_time in xrange(self.n_updates_per_sample):
+ for update_time in range(self.n_updates_per_sample):
batch = memory.get_batch(self.batch_size)
self.do_update(itr, batch)
diff --git a/example/ssd/dataset/pycocotools/coco.py b/example/ssd/dataset/pycocotools/coco.py
index a8939f6..19a7b8b 100755
--- a/example/ssd/dataset/pycocotools/coco.py
+++ b/example/ssd/dataset/pycocotools/coco.py
@@ -55,12 +55,12 @@ import itertools
# from . import mask as maskUtils
import os
from collections import defaultdict
-import sys
-PYTHON_VERSION = sys.version_info[0]
-if PYTHON_VERSION == 2:
- from urllib import urlretrieve
-elif PYTHON_VERSION == 3:
+from mxnet.base import string_types
+try:
from urllib.request import urlretrieve
+except ImportError:
+ from urllib import urlretrieve
+
class COCO:
def __init__(self, annotation_file=None):
@@ -302,7 +302,7 @@ class COCO:
print('Loading and preparing results...')
tic = time.time()
- if type(resFile) == str or type(resFile) == unicode:
+ if type(resFile) in string_types:
anns = json.load(open(resFile))
elif type(resFile) == np.ndarray:
anns = self.loadNumpyAnnotations(resFile)