apeforest commented on a change in pull request #17242: add RandomApply in
gluon's transforms
URL: https://github.com/apache/incubator-mxnet/pull/17242#discussion_r363944967
##########
File path: tests/python/unittest/test_gluon_data_vision.py
##########
@@ -229,6 +229,21 @@ def test_transformer():
transform(mx.nd.ones((245, 480, 3), dtype='uint8')).wait_to_read()
+@with_seed()
+def test_randomtransforms():
+ from mxnet.gluon.data.vision import transforms
+
+ transform =
transforms.Compose([transforms.RandomApply(transforms.Compose([transforms.Resize(300),
transforms.RandomResizedCrop(224)]), 0.5)])
+
+ img = mx.nd.ones((245, 480, 3), dtype='uint8')
+ iteration = 1000
+ num_apply = 0
+ for i in range(iteration):
+ out = transform(img)
+ if out.shape[0] == 224:
+ num_apply += 1
+ assert(abs(num_apply/float(iteration)-0.5) < 1e-1)
Review comment:
Use `assert_almost_equal` from test_util?
https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/test_utils.py
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services