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 2018/01/03 02:46:18 UTC
[GitHub] feevos opened a new issue #9288: Get HybridBlock layer shape on runtime
feevos opened a new issue #9288: Get HybridBlock layer shape on runtime
URL: https://github.com/apache/incubator-mxnet/issues/9288
Dear all,
I am trying to build a custom pooling layer (both for ndarray and Symbol) and I need to know the input shape at runtime. According to the documentation, HybridBlock has the function "infer_shape", but I can't make it work. Any pointers into what I am doing wrong?
## mxnet version
1.0.0 , build from conda, python3.
## Minimum reproducible example
For example:
```Python
import mxnet as mx
import mxnet.ndarray as nd
from mxnet.gluon import HybridBlock
class runtime_shape(HybridBlock):
def __init__(self, **kwards):
HybridBlock.__init__(self,**kwards)
def hybrid_forward(self,F,_input):
print (self.infer_shape(_input))
return _input
xx = nd.random_uniform(shape=[5,5,16,16])
mynet = runtime_shape()
mynet.hybrid_forward(nd,xx)
```
## Error Message:
```Python
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-41-3f539a940958> in <module>()
----> 1 mynet.hybrid_forward(nd,xx)
<ipython-input-38-afc9785b716d> in hybrid_forward(self, F, _input)
17 def hybrid_forward(self,F,_input):
18
---> 19 print (self.infer_shape(_input))
20
21 return _input
/home/dia021/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.pyc in infer_shape(self, *args)
460 def infer_shape(self, *args):
461 """Infers shape of Parameters from inputs."""
--> 462 self._infer_attrs('infer_shape', 'shape', *args)
463
464 def infer_type(self, *args):
/home/dia021/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.pyc in _infer_attrs(self, infer_fn, attr, *args)
448 def _infer_attrs(self, infer_fn, attr, *args):
449 """Generic infer attributes."""
--> 450 inputs, out = self._get_graph(*args)
451 args, _ = _flatten(args)
452 arg_attrs, _, aux_attrs = getattr(out, infer_fn)(
/home/dia021/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.pyc in _get_graph(self, *args)
369 params = {i: j.var() for i, j in self._reg_params.items()}
370 with self.name_scope():
--> 371 out = self.hybrid_forward(symbol, *grouped_inputs, **params) # pylint: disable=no-value-for-parameter
372 out, self._out_format = _flatten(out)
373
/home/dia021/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.pyc in __exit__(self, ptype, value, trace)
78 if self._block._empty_prefix:
79 return
---> 80 self._name_scope.__exit__(ptype, value, trace)
81 self._name_scope = None
82 _BlockScope._current = self._old_scope
AttributeError: 'NoneType' object has no attribute '__exit__'
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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