You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by sk...@apache.org on 2019/01/26 00:54:26 UTC
[incubator-mxnet] branch master updated: Sample python bilinear
initializer at integral points in y-direction (#12983)
This is an automated email from the ASF dual-hosted git repository.
skm 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 28c20fb Sample python bilinear initializer at integral points in y-direction (#12983)
28c20fb is described below
commit 28c20fb6c1ad66548336c817d07031ccbbccf435
Author: vlado <vl...@gmail.com>
AuthorDate: Fri Jan 25 17:54:10 2019 -0700
Sample python bilinear initializer at integral points in y-direction (#12983)
* Sample python bilinear initializer at integral points in y-direction
* Add unit test for bilinear initializer
---
python/mxnet/initializer.py | 4 ++--
tests/python/unittest/test_init.py | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/python/mxnet/initializer.py b/python/mxnet/initializer.py
index b67ab62..611592a 100755
--- a/python/mxnet/initializer.py
+++ b/python/mxnet/initializer.py
@@ -217,7 +217,7 @@ class Initializer(object):
c = (2 * f - 1 - f % 2) / (2. * f)
for i in range(np.prod(shape)):
x = i % shape[3]
- y = (i / shape[3]) % shape[2]
+ y = (i // shape[3]) % shape[2]
weight[i] = (1 - abs(x / f - c)) * (1 - abs(y / f - c))
arr[:] = weight.reshape(shape)
@@ -657,7 +657,7 @@ class Bilinear(Initializer):
c = (2 * f - 1 - f % 2) / (2. * f)
for i in range(np.prod(shape)):
x = i % shape[3]
- y = (i / shape[3]) % shape[2]
+ y = (i // shape[3]) % shape[2]
weight[i] = (1 - abs(x / f - c)) * (1 - abs(y / f - c))
arr[:] = weight.reshape(shape)
diff --git a/tests/python/unittest/test_init.py b/tests/python/unittest/test_init.py
index efd6ef3..c8bf01f 100644
--- a/tests/python/unittest/test_init.py
+++ b/tests/python/unittest/test_init.py
@@ -60,8 +60,17 @@ def test_rsp_const_init():
check_rsp_const_init(mx.initializer.Zero(), 0.)
check_rsp_const_init(mx.initializer.One(), 1.)
+def test_bilinear_init():
+ bili = mx.init.Bilinear()
+ bili_weight = mx.ndarray.empty((1,1,4,4))
+ bili._init_weight(None, bili_weight)
+ bili_1d = np.array([[1/float(4), 3/float(4), 3/float(4), 1/float(4)]])
+ bili_2d = bili_1d * np.transpose(bili_1d)
+ assert (bili_2d == bili_weight.asnumpy()).all()
+
if __name__ == '__main__':
test_variable_init()
test_default_init()
test_aux_init()
test_rsp_const_init()
+ test_bilinear_init()