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 2020/03/10 14:56:31 UTC
[GitHub] [incubator-mxnet] aGiant opened a new issue #17800: _MinusScalar
type not supported` ?
aGiant opened a new issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800
```
<ipython-input-92-6fb5c4df8b27> in hybrid_forward(self, F, x)
36 #x = self.normalizer(data)
37 flat_x = self.flatten(x)
---> 38 above = flat_x - self.min
39 under = self.max - self.min
40 x_normalized = above/under
~/anaconda3/lib/python3.7/site-packages/mxnet/symbol/symbol.py in __sub__(self, other)
127 return _internal._MinusScalar(self, scalar=other)
128 else:
--> 129 raise TypeError('type %s not supported' % str(type(other)))
130
131 def __isub__(self, other):
TypeError: type <class 'mxnet.ndarray.ndarray.NDArray'> not supported
```
those are defined in hybrid_forward of official VAE code example.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented 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'>)
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] leezu commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
leezu commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597264160
No. net(x)
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant removed a comment on issue #17800:
_MinusScalar type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant removed a comment on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597175578
Tried min-max normalization with given min-max values based on https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/custom_layer_beginners.html:
```
--------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-175-2d25ca5fd6d4> in <module>
6 model_prefix = 'vae_gluon_{}d{}l{}h.params'.format(n_latent, n_layers, n_hidden)
7
----> 8 net = VAE(n_hidden, n_latent, n_layers, n_output, min_v.values, max_v.values)
<ipython-input-174-2c3888550b32> in __init__(self, n_hidden, n_latent, n_layers, n_output, min_vec, max_vec, act_type, **kwargs)
13 # self.max_v = max_vec #mx.gluon.Constant('max_v', max_vec)
14 print(dir(self))
---> 15 self.min_v = self.params.get('scales_min',
16 shape=scales.shape,
17 init=mx.init.Constant(min_vec),
~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in params(self)
268 """Returns this :py:class:`Block`'s parameter dictionary (does not include its
269 children's parameters)."""
--> 270 return self._params
271
272 def collect_params(self, select=None):
AttributeError: 'VAE' object has no attribute '_params'
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant edited a comment on issue #17800:
_MinusScalar type not supported` ?
Posted by GitBox <gi...@apache.org>.
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'>)
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] leezu commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
leezu commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597208855
`hybrid_forward(self, F, x, min_v, max_v):` still mean users call the `net(x)`, with `min_v, max_v` being automatically passed and taking the value of the constants.
My point is that you're not using the hybridize API correctly, thus the link to the documentation.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597207080
> `self.min_v` is a constant parameter. In the current `hybrid_forward` API, you need to `def hybrid_forward(self, F, x, min_v, max_v):` and you'll get the ndarray associated with the parameter as an argument.
>
> The API will be simplified with #17530
>
> You can read https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/hybridize.html
Your solution is based on the assumption that all the min-max values were already prepared or at least accessible. Our problem from production environment is that the final user or platform does not have the access to gather the min-max values.
One possible solution for our problem in production is to save the min-max values default within the NN as constant vectors.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597210313
> `self.min_v` is a constant parameter. In the current `hybrid_forward` API, you need to `def hybrid_forward(self, F, x, min_v, max_v):` and you'll get the ndarray associated with the parameter as an argument.
>
> The API will be simplified with #17530
>
> You can read https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/hybridize.html
Or in short, our final user just have the x, they do not have any min_v and max_v basedon
> link
Could you pleas point out the errors? I have already visited that links many times from last month.
Many thanks!
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant edited a comment on issue #17800:
_MinusScalar type not supported` ?
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597273750
By calling net(x):
```
~/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), \
TypeError: hybrid_forward() missing 2 required positional arguments: 'min_v' and 'max_v'
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597157035
More errors
```
<ipython-input-133-18747e174c30> in __init__(self, n_hidden, n_latent, n_layers, n_output, min_vec, max_vec, act_type, **kwargs)
11 # https://mxnet.apache.org/api/python/docs/api/gluon/constant.html
12 # self.const = self.params.get_constant('const', [[1,2],[3,4]])
---> 13 self.min_v = mx.gluon.Constant('const_min', min_vec)
14 self.max_v = mx.gluon.Constant('const_max', max_vec)
15 # note to self: requring batch_size in model definition is sad,
~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in __setattr__(self, name, value)
732 def __setattr__(self, name, value):
733 """Registers parameters."""
--> 734 super(HybridBlock, self).__setattr__(name, value)
735 if isinstance(value, HybridBlock):
736 self._clear_cached_op()
~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in __setattr__(self, name, value)
202 self.register_child(value, name)
203 elif isinstance(value, Parameter):
--> 204 assert name not in self._reg_params, \
205 "Overriding Parameter attribute %s is not allowed. " \
206 "If you want to share parameters between blocks, please set " \
AttributeError: 'VAE' object has no attribute '_reg_params'
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597175578
Tried min-max normalization with given min-max values based on https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/custom_layer_beginners.html:
```
--------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-175-2d25ca5fd6d4> in <module>
6 model_prefix = 'vae_gluon_{}d{}l{}h.params'.format(n_latent, n_layers, n_hidden)
7
----> 8 net = VAE(n_hidden, n_latent, n_layers, n_output, min_v.values, max_v.values)
<ipython-input-174-2c3888550b32> in __init__(self, n_hidden, n_latent, n_layers, n_output, min_vec, max_vec, act_type, **kwargs)
13 # self.max_v = max_vec #mx.gluon.Constant('max_v', max_vec)
14 print(dir(self))
---> 15 self.min_v = self.params.get('scales_min',
16 shape=scales.shape,
17 init=mx.init.Constant(min_vec),
~/anaconda3/lib/python3.7/site-packages/mxnet/gluon/block.py in params(self)
268 """Returns this :py:class:`Block`'s parameter dictionary (does not include its
269 children's parameters)."""
--> 270 return self._params
271
272 def collect_params(self, select=None):
AttributeError: 'VAE' object has no attribute '_params'
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] leezu commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
leezu commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597224296
The parameters (constant or not), are handled special in the current hybrid_forward API.
You can see the implementation:
https://github.com/apache/incubator-mxnet/blob/afb8742e6e1e987833b39c487dc892b5537196a1/python/mxnet/gluon/block.py#L1204-L1206
So you should use `hybrid_forward(self, F, x, min_v, max_v):` and not access `self.min_v` inside the hybrid_forward.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] leezu commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
leezu commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597203564
`self.min_v` is a constant parameter. In the current `hybrid_forward` API, you need to `def hybrid_forward(self, F, x, min_v, max_v):` and you'll get the ndarray associated with the parameter as an argument.
The API will be simplified with https://github.com/apache/incubator-mxnet/pull/17530
You can read https://mxnet.apache.org/api/python/docs/tutorials/packages/gluon/blocks/hybridize.html
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] leezu closed issue #17800: _MinusScalar type
not supported` ?
Posted by GitBox <gi...@apache.org>.
leezu closed issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597135956
Maybe I was too old to count the number ;)
```
model_ctx = mx.gpu()
<ipython-input-102-09c5bc45d5b4> in hybrid_forward(self, F, x)
35 def hybrid_forward(self, F, x):
36 #x = self.normalizer(data)
---> 37 x.as_in_context(model_ctx)
38 flat_x = self.flatten(x)
39 above = flat_x - self.min
TypeError: **as_in_context() takes 1 positional argument but 2 were given**
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] ptrendx commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
ptrendx commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-606925771
@aGiant You are still using `self.min_v` and `self.max_v` in your `hybrid_forward`. Are you sure you have them set as parameters? Here is a simple working example of using parameters:
```python
class Test(gluon.HybridBlock):
def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
with self.name_scope():
self.x_min = self.params.get('scales_min',
shape=(1,),
init=mx.init.Constant(5),
differentiable=False)
self.x_max = self.params.get('scales_max',
shape=(1,),
init=mx.init.Constant(10),
differentiable=False)
def hybrid_forward(self, F, x, x_min, x_max):
return (x * x_min) + x_max
t = Test()
t.initialize()
t(mx.nd.ones((1,)))
```
```python
[15.]
<NDArray 1 @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
[GitHub] [incubator-mxnet] aGiant edited a comment on issue #17800:
_MinusScalar type not supported` ?
Posted by GitBox <gi...@apache.org>.
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)
```
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597279061
> No. net(x)
```
def hybrid_forward(self, F, x, min_v, max_v):
#x = self.normalizer(data)
#x_normalized = F.broadcast_div(F.broadcast_sub(self.flatten(x), self.min_v), (F.broadcast_sub(self.max_v, self.min_v)))
x_normalized = self.trans(x) - min_v
h = self.encoder(x_normalized)
#print(h.asnumpy()[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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597227128
> The parameters (constant or not), are handled special in the current hybrid_forward API.
>
> You can see the implementation:
>
> https://github.com/apache/incubator-mxnet/blob/afb8742e6e1e987833b39c487dc892b5537196a1/python/mxnet/gluon/block.py#L1204-L1206
>
> So you should use `hybrid_forward(self, F, x, min_v, max_v):` and not access `self.min_v` inside the hybrid_forward.
The by calling for prediction, our client must use net(x, min_v, max_v), right? But they do not have any access to prepare the min_v and max_v in production.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597213200
> `hybrid_forward(self, F, x, min_v, max_v):` still mean users call the `net(x)`, with `min_v, max_v` being automatically passed and taking the value of the constants.
>
> My point is that you're not using the hybridize API correctly, thus the link to the documentation.
Because from official link in hybird_forward:
```
return (x - nd.min(x)) / (nd.max(x) - nd.min(x))
```
this works very well, but
```
return (x - self.min_v)
```
did not work.
----------------------------------------------------------------
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
[GitHub] [incubator-mxnet] aGiant commented on issue #17800: _MinusScalar
type not supported` ?
Posted by GitBox <gi...@apache.org>.
aGiant commented on issue #17800: _MinusScalar type <class 'mxnet.ndarray.ndarray.NDArray'> not supported` ?
URL: https://github.com/apache/incubator-mxnet/issues/17800#issuecomment-597205465
Then min-max values must be prepared outsides the NN, our plan is to save the min-max as constant within at the initial stage of NN, and all trained model with be saved and transferred to other platform without any preparation of min-max values in production environment such as from Spark.
The problem based on your link was not solved.
----------------------------------------------------------------
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