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/03/21 12:50:59 UTC

[GitHub] [incubator-mxnet] EvenIsLee opened a new issue #14490: initializer not work excepted

EvenIsLee opened a new issue #14490: initializer not work excepted
URL: https://github.com/apache/incubator-mxnet/issues/14490
 
 
   when I use @mx.init.register to set a new initializer, bias and others not update excepted. Only weight is changed.
   
   ```
   import mxnet as mx
   from mxnet.gluon import nn
   
   @mx.init.register
   class MyInit(mx.init.Initializer):
       def __init__(self, **kwargs):
           super(MyInit, self).__init__(**kwargs)
           #self._verbose_print=True
       def _init_weight(self, name, arr):
           arr[:] = 0.5
   
       def _init_bias(self, name, arr):
           arr[:] = 1.0
   
       def _init_gamma(self, name, arr):
           arr[:] = 2.0
   
       def _init_default(self, name, arr):
           arr[:] = 2.0
      
   class Mymodel(nn.Block):
       def __init__(self):
           super(Mymodel, self).__init__()
   
           with self.name_scope():
               self.dense = nn.Dense(128, in_units=16)
               self.bn = nn.BatchNorm()
   
       def forward(self, x):
           x = self.dense(x)
           x = self.bn(x)
           return x
   
   if __name__=='__main__':
       data = mx.nd.random.uniform(shape=(1, 16))
       net = Mymodel()
       net.initialize(MyInit())
       net(data)
       print net.dense.weight.data()
       print net.dense.bias.data()
       print net.bn.gamma.data()
   
   ```
   these are outputs
   
   ```
   [[0.5 0.5 0.5 ... 0.5 0.5 0.5]
    [0.5 0.5 0.5 ... 0.5 0.5 0.5]
    [0.5 0.5 0.5 ... 0.5 0.5 0.5]
    ...
    [0.5 0.5 0.5 ... 0.5 0.5 0.5]
    [0.5 0.5 0.5 ... 0.5 0.5 0.5]
    [0.5 0.5 0.5 ... 0.5 0.5 0.5]]
   <NDArray 128x16 @cpu(0)>
   
   [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
    0. 0. 0. 0. 0. 0. 0. 0.]
   <NDArray 128 @cpu(0)>
   
   [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
    1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
    1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
    1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
    1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
    1. 1. 1. 1. 1. 1. 1. 1.]
   <NDArray 128 @cpu(0)>
   ```

----------------------------------------------------------------
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