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 2018/07/26 04:24:02 UTC
[GitHub] sandeep-krishnamurthy closed pull request #11864: [MXNET-664]
Support integer type in ImageIter
sandeep-krishnamurthy closed pull request #11864: [MXNET-664] Support integer type in ImageIter
URL: https://github.com/apache/incubator-mxnet/pull/11864
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/python/mxnet/image/image.py b/python/mxnet/image/image.py
index 5af2b955665..c2a1906646f 100644
--- a/python/mxnet/image/image.py
+++ b/python/mxnet/image/image.py
@@ -1057,6 +1057,8 @@ class ImageIter(io.DataIter):
Data name for provided symbols.
label_name : str
Label name for provided symbols.
+ dtype : str
+ Label data type. Default: float32. Other options: int32, int64, float64
kwargs : ...
More arguments for creating augmenter. See mx.image.CreateAugmenter.
"""
@@ -1064,9 +1066,10 @@ class ImageIter(io.DataIter):
def __init__(self, batch_size, data_shape, label_width=1,
path_imgrec=None, path_imglist=None, path_root=None, path_imgidx=None,
shuffle=False, part_index=0, num_parts=1, aug_list=None, imglist=None,
- data_name='data', label_name='softmax_label', **kwargs):
+ data_name='data', label_name='softmax_label', dtype='float32', **kwargs):
super(ImageIter, self).__init__()
assert path_imgrec or path_imglist or (isinstance(imglist, list))
+ assert dtype in ['int32', 'float32', 'int64', 'float64'], dtype + ' label not supported'
num_threads = os.environ.get('MXNET_CPU_WORKER_NTHREADS', 1)
logging.info('Using %s threads for decoding...', str(num_threads))
logging.info('Set enviroment variable MXNET_CPU_WORKER_NTHREADS to a'
@@ -1091,7 +1094,7 @@ def __init__(self, batch_size, data_shape, label_width=1,
imgkeys = []
for line in iter(fin.readline, ''):
line = line.strip().split('\t')
- label = nd.array([float(i) for i in line[1:-1]])
+ label = nd.array(line[1:-1], dtype=dtype)
key = int(line[0])
imglist[key] = (label, line[-1])
imgkeys.append(key)
@@ -1105,11 +1108,11 @@ def __init__(self, batch_size, data_shape, label_width=1,
key = str(index) # pylint: disable=redefined-variable-type
index += 1
if len(img) > 2:
- label = nd.array(img[:-1])
+ label = nd.array(img[:-1], dtype=dtype)
elif isinstance(img[0], numeric_types):
- label = nd.array([img[0]])
+ label = nd.array([img[0]], dtype=dtype)
else:
- label = nd.array(img[0])
+ label = nd.array(img[0], dtype=dtype)
result[key] = (label, img[-1])
imgkeys.append(str(key))
self.imglist = result
diff --git a/tests/python/unittest/test_image.py b/tests/python/unittest/test_image.py
index 636c5e2be67..9eec1835c1f 100644
--- a/tests/python/unittest/test_image.py
+++ b/tests/python/unittest/test_image.py
@@ -132,26 +132,33 @@ def test_color_normalize(self):
def test_imageiter(self):
- im_list = [[np.random.randint(0, 5), x] for x in TestImage.IMAGES]
- test_iter = mx.image.ImageIter(2, (3, 224, 224), label_width=1, imglist=im_list,
- path_root='')
- for _ in range(3):
+ def check_imageiter(dtype='float32'):
+ im_list = [[np.random.randint(0, 5), x] for x in TestImage.IMAGES]
+ test_iter = mx.image.ImageIter(2, (3, 224, 224), label_width=1, imglist=im_list,
+ path_root='', dtype=dtype)
+ for _ in range(3):
+ for batch in test_iter:
+ pass
+ test_iter.reset()
+
+ # test with list file
+ fname = './data/test_imageiter.lst'
+ file_list = ['\t'.join([str(k), str(np.random.randint(0, 5)), x]) \
+ for k, x in enumerate(TestImage.IMAGES)]
+ with open(fname, 'w') as f:
+ for line in file_list:
+ f.write(line + '\n')
+
+ test_iter = mx.image.ImageIter(2, (3, 224, 224), label_width=1, path_imglist=fname,
+ path_root='', dtype=dtype)
for batch in test_iter:
pass
- test_iter.reset()
- # test with list file
- fname = './data/test_imageiter.lst'
- file_list = ['\t'.join([str(k), str(np.random.randint(0, 5)), x]) \
- for k, x in enumerate(TestImage.IMAGES)]
- with open(fname, 'w') as f:
- for line in file_list:
- f.write(line + '\n')
+ for dtype in ['int32', 'float32', 'int64', 'float64']:
+ check_imageiter(dtype)
- test_iter = mx.image.ImageIter(2, (3, 224, 224), label_width=1, path_imglist=fname,
- path_root='')
- for batch in test_iter:
- pass
+ # test with default dtype
+ check_imageiter()
@with_seed()
def test_augmenters(self):
----------------------------------------------------------------
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