Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
piiswrong committed Jan 22, 2018
1 parent 62ffb92 commit ab0d1d5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions docker/install/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ apt-get update && apt-get install -y python-dev python3-dev
# the version of the pip shipped with ubuntu may be too lower, install a recent version here
cd /tmp && wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py && python2 get-pip.py

pip2 install nose pylint numpy nose-timer requests
pip3 install nose pylint numpy nose-timer requests
pip2 install nose pylint numpy nose-timer requests Pillow
pip3 install nose pylint numpy nose-timer requests Pillow
2 changes: 2 additions & 0 deletions python/mxnet/gluon/data/vision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# under the License.

# coding: utf-8
# pylint: disable=wildcard-import
"""Vision utilities."""

from .datasets import *

Expand Down
7 changes: 4 additions & 3 deletions python/mxnet/gluon/data/vision/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# under the License.

# coding: utf-8
# pylint: disable= arguments-differ
"Image transforms."

from .. import dataset
from ...block import Block, HybridBlock
from ...nn import Sequential, HybridSequential
from .... import ndarray, initializer, image
from ....base import _Null, numeric_types
from .... import image
from ....base import numeric_types


class Compose(Sequential):
Expand Down
3 changes: 2 additions & 1 deletion python/mxnet/ndarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
from .sparse import _ndarray_cls
from .ndarray import _GRAD_REQ_MAP

__all__ = op.__all__ + ndarray.__all__ + utils.__all__ + ['contrib', 'linalg', 'random', 'sparse', 'image']
__all__ = op.__all__ + ndarray.__all__ + utils.__all__ + \
['contrib', 'linalg', 'random', 'sparse', 'image']
2 changes: 1 addition & 1 deletion src/operator/image/image_random-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ template<typename DType, int axis>
void FlipImpl(const TShape &shape, DType *src, DType *dst) {
int head = 1, mid = shape[axis], tail = 1;
for (int i = 0; i < axis; ++i) head *= shape[i];
for (int i = axis+1; i < shape.ndim(); ++i) tail *= shape[i];
for (uint32_t i = axis+1; i < shape.ndim(); ++i) tail *= shape[i];

for (int i = 0; i < head; ++i) {
for (int j = 0; j < (mid >> 1); ++j) {
Expand Down
21 changes: 0 additions & 21 deletions tests/python/unittest/test_gluon_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,6 @@ def test_multi_worker():
assert (batch.asnumpy() == i).all()


def test_transformer():
from mxnet.gluon.data.vision import transforms

transform = transforms.Compose([
transforms.Resize(300),
transforms.CenterCrop(256),
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.RandomColorJitter(0.1, 0.1, 0.1, 0.1),
transforms.RandomBrightness(0.1),
transforms.RandomContrast(0.1),
transforms.RandomSaturation(0.1),
transforms.RandomHue(0.1),
transforms.RandomLighting(0.1),
transforms.ToTensor(),
transforms.Normalize([0, 0, 0], [1, 1, 1])])

transform(mx.nd.ones((245, 480, 3), dtype='uint8')).wait_to_read()


if __name__ == '__main__':
test_transformer()
import nose
nose.runmodule()
31 changes: 26 additions & 5 deletions tests/python/unittest/test_gluon_data_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import mxnet as mx
import mxnet.ndarray as nd
import numpy as np
from PIL import Image
from mxnet import gluon
from mxnet.gluon.data.vision import transforms
from mxnet.test_utils import assert_almost_equal
Expand All @@ -42,15 +41,37 @@ def test_normalize():

def test_flip_left_right():
data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8)
pil_img = Image.fromarray(data_in).transpose(Image.FLIP_LEFT_RIGHT)
flip_in = data_in[:, ::-1, :]
data_trans = nd.image.flip_left_right(nd.array(data_in, dtype='uint8'))
assert_almost_equal(np.array(pil_img), data_trans.asnumpy())
assert_almost_equal(flip_in, data_trans.asnumpy())

def test_flip_top_bottom():
data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8)
pil_img = Image.fromarray(data_in).transpose(Image.FLIP_TOP_BOTTOM)
flip_in = data_in[::-1, :, :]
data_trans = nd.image.flip_top_bottom(nd.array(data_in, dtype='uint8'))
assert_almost_equal(np.array(pil_img), data_trans.asnumpy())
assert_almost_equal(flip_in, data_trans.asnumpy())


def test_transformer():
from mxnet.gluon.data.vision import transforms

transform = transforms.Compose([
transforms.Resize(300),
transforms.CenterCrop(256),
transforms.RandomResizedCrop(224),
transforms.RandomFlipLeftRight(),
transforms.RandomColorJitter(0.1, 0.1, 0.1, 0.1),
transforms.RandomBrightness(0.1),
transforms.RandomContrast(0.1),
transforms.RandomSaturation(0.1),
transforms.RandomHue(0.1),
transforms.RandomLighting(0.1),
transforms.ToTensor(),
transforms.Normalize([0, 0, 0], [1, 1, 1])])

transform(mx.nd.ones((245, 480, 3), dtype='uint8')).wait_to_read()



if __name__ == '__main__':
import nose
Expand Down

0 comments on commit ab0d1d5

Please sign in to comment.