aGiant edited a comment on issue #17800: _MinusScalar type <class 
'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: 
https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597183356
 
 
   Just tried example from 
https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/custom_layer_beginners.html
 to build ** min-max normalization using saved min-max values**, but more and 
more errors:
   ```
   --------------------------------------------------------------------
   AssertionError                     Traceback (most recent call last)
   <ipython-input-213-cbd52c8ac2cb> in <module>
         2 net.collect_params().initialize(mx.init.Xavier(), ctx=model_ctx)
         3 #net(mx.nd.random.uniform(shape=(128,feature_n), ctx=model_ctx))
   ----> 4 print(net.summary(mx.nd.random.uniform(shape=(1,feature_n), 
ctx=model_ctx)))
         5 net.hybridize()
         6 trainer = gluon.Trainer(net.collect_params(), 'SGD', {'wd':0.01}) 
#'learning_rate': .001,
   
   ~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in 
summary(self, *inputs)
       648         try:
       649             self.apply(_register_summary_hook)
   --> 650             self(*inputs)
       651 
       652             line_format = '{:>20}  {:>42} {:>15}'
   
   ~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in 
__call__(self, *args)
       546             hook(self, args)
       547 
   --> 548         out = self.forward(*args)
       549 
       550         for hook in self._forward_hooks.values():
   
   <ipython-input-211-58f911007fa2> in forward(self, x)
        43     def forward(self,x):
        44         self.batch_size = x.shape[0]
   ---> 45         return gluon.HybridBlock.forward(self, x)
        46 
        47     # 
https://mxnet.apache.org/api/python/docs/tutorials/extend/custom_layer.html
   
   ~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in 
forward(self, x, *args)
       923                     params = {i: j.data(ctx) for i, j in 
self._reg_params.items()}
       924 
   --> 925                 return self.hybrid_forward(ndarray, x, *args, 
**params)
       926 
       927         assert isinstance(x, Symbol), \
   
   <ipython-input-211-58f911007fa2> in hybrid_forward(self, F, x)
        49     def hybrid_forward(self, F, x):
        50         #x = self.normalizer(data)
   ---> 51         x_normalized = 
F.broadcast_div(F.broadcast_sub(self.flatten(x), self.min_v), 
(F.broadcast_sub(self.max_v, self.min_v)))
        52         h = self.encoder(x_normalized)
        53         #print(h.asnumpy()[0])
   
   ~/anaconda3/lib/python3.7/site-packages/mxnet/ndarray/register.py in 
broadcast_sub(lhs, rhs, out, name, **kwargs)
   
   AssertionError: Argument rhs must have NDArray type, but got Parameter 
vae54_scales_min (shape=(70,), dtype=<class 'numpy.float32'>)
   
   
   ```
   
   Saved constant min-max values:
   ```
           self.min_v = self.params.get('scales_min',
                                         shape=min_vec.shape,
                                         init=mx.init.Constant(min_vec),
                                         differentiable=False)
           self.max_v = self.params.get('scales_max',
                                         shape=max_vec.shape,
                                         init=mx.init.Constant(max_vec),
                                         differentiable=False)
   ```
   
   Also tried 
   ```
           self.min_v = mx.gluon.Constant('min_v', min_vec)
           self.max_v = mx.gluon.Constant('max_v', max_vec) 
   ```
   but got similar error:
   ```
   <ipython-input-214-026df9c27e7e> in hybrid_forward(self, F, x)
        49     def hybrid_forward(self, F, x):
        50         #x = self.normalizer(data)
   ---> 51         x_normalized = 
F.broadcast_div(F.broadcast_sub(self.flatten(x), self.min_v), 
(F.broadcast_sub(self.max_v, self.min_v)))
        52         h = self.encoder(x_normalized)
        53         #print(h.asnumpy()[0])
   
   ~/anaconda3/lib/python3.7/site-packages/mxnet/ndarray/register.py in 
broadcast_sub(lhs, rhs, out, name, **kwargs)
   
   AssertionError: Argument rhs must have NDArray type, but got Constant min_v 
(shape=(70,), dtype=<class 'numpy.float32'>)
   ```

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

Reply via email to