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 2019/10/15 22:13:48 UTC
[GitHub] [incubator-mxnet] roywei commented on a change in pull request
#16464: Image crop gpu support
roywei commented on a change in pull request #16464: Image crop gpu support
URL: https://github.com/apache/incubator-mxnet/pull/16464#discussion_r335201026
##########
File path: tests/python/gpu/test_gluon_transforms.py
##########
@@ -28,76 +28,19 @@
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
sys.path.insert(0, os.path.join(curr_path, '../unittest'))
from common import assertRaises, setup_module, with_seed, teardown
-
+from test_gluon_data_vision import test_to_tensor, test_normalize, test_crop_resize
set_default_context(mx.gpu(0))
@with_seed()
-def test_normalize():
- # 3D Input
- data_in_3d = nd.random.uniform(0, 1, (3, 300, 300))
- out_nd_3d = transforms.Normalize(mean=(0, 1, 2), std=(3, 2, 1))(data_in_3d)
- data_expected_3d = data_in_3d.asnumpy()
- data_expected_3d[:][:][0] = data_expected_3d[:][:][0] / 3.0
- data_expected_3d[:][:][1] = (data_expected_3d[:][:][1] - 1.0) / 2.0
- data_expected_3d[:][:][2] = data_expected_3d[:][:][2] - 2.0
- assert_almost_equal(data_expected_3d, out_nd_3d.asnumpy())
-
- # 4D Input
- data_in_4d = nd.random.uniform(0, 1, (2, 3, 300, 300))
- out_nd_4d = transforms.Normalize(mean=(0, 1, 2), std=(3, 2, 1))(data_in_4d)
- data_expected_4d = data_in_4d.asnumpy()
- data_expected_4d[0][:][:][0] = data_expected_4d[0][:][:][0] / 3.0
- data_expected_4d[0][:][:][1] = (data_expected_4d[0][:][:][1] - 1.0) / 2.0
- data_expected_4d[0][:][:][2] = data_expected_4d[0][:][:][2] - 2.0
- data_expected_4d[1][:][:][0] = data_expected_4d[1][:][:][0] / 3.0
- data_expected_4d[1][:][:][1] = (data_expected_4d[1][:][:][1] - 1.0) / 2.0
- data_expected_4d[1][:][:][2] = data_expected_4d[1][:][:][2] - 2.0
- assert_almost_equal(data_expected_4d, out_nd_4d.asnumpy())
-
- # Default normalize values i.e., mean=0, std=1
- data_in_3d_def = nd.random.uniform(0, 1, (3, 300, 300))
- out_nd_3d_def = transforms.Normalize()(data_in_3d_def)
- data_expected_3d_def = data_in_3d_def.asnumpy()
- assert_almost_equal(data_expected_3d_def, out_nd_3d_def.asnumpy())
+def test_normalize_gpu():
+ test_normalize()
- # Invalid Input - Neither 3D or 4D input
- invalid_data_in = nd.random.uniform(0, 1, (5, 5, 3, 300, 300))
- normalize_transformer = transforms.Normalize(mean=(0, 1, 2), std=(3, 2, 1))
- assertRaises(MXNetError, normalize_transformer, invalid_data_in)
-
- # Invalid Input - Channel neither 1 or 3
- invalid_data_in = nd.random.uniform(0, 1, (5, 4, 300, 300))
- normalize_transformer = transforms.Normalize(mean=(0, 1, 2), std=(3, 2, 1))
- assertRaises(MXNetError, normalize_transformer, invalid_data_in)
@with_seed()
-def test_to_tensor():
- # 3D Input
- data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8)
- out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8'))
- assert_almost_equal(out_nd.asnumpy(), np.transpose(
- data_in.astype(dtype=np.float32) / 255.0, (2, 0, 1)))
-
- # 4D Input
- data_in = np.random.uniform(0, 255, (5, 300, 300, 3)).astype(dtype=np.uint8)
- out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8'))
- assert_almost_equal(out_nd.asnumpy(), np.transpose(
- data_in.astype(dtype=np.float32) / 255.0, (0, 3, 1, 2)))
+def test_to_tensor_gpu():
+ test_to_tensor()
- # Invalid Input
- invalid_data_in = nd.random.uniform(0, 255, (5, 5, 300, 300, 3)).astype(dtype=np.uint8)
- transformer = transforms.ToTensor()
- assertRaises(MXNetError, transformer, invalid_data_in)
-
- # Bounds (0->0, 255->1)
- data_in = np.zeros((10, 20, 3)).astype(dtype=np.uint8)
- out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8'))
- assert same(out_nd.asnumpy(), np.transpose(np.zeros(data_in.shape, dtype=np.float32), (2, 0, 1)))
-
- data_in = np.full((10, 20, 3), 255).astype(dtype=np.uint8)
- out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8'))
- assert same(out_nd.asnumpy(), np.transpose(np.ones(data_in.shape, dtype=np.float32), (2, 0, 1)))
@with_seed()
def test_resize():
Review comment:
can you rename this to test_resize_gpu for consistency, so people know there is a difference from test_resize()
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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