I changed the shape of alpha as pilswrong suggested, but it seems I have not done it correctly. But I’m unclear how to fix and I seek advice.
class Prlu(Block):
def __init__(self, units, **kwargs):
super(Prlu, self).__init__(**kwargs)
with self.name_scope():
self.units = units
#################
# We add the required parameters to the ``Block``'s ParameterDict
# want alpha set to 1.0, then learned after that.
#################
self.alpha = self.params.get(
'alpha', init=mx.initializer.One(),
shape=(units,1,1,))
# __subex will become a more complicated formula
def __subex(self, x):
return ((x>=0)+(x<0)*self.alpha.data())
def forward(self, x):
return (x*self.__subex(x))
When I define the network in the way it makes sense to me by specifying the shape
of the fully connected layer “net.add(Prlu(128))”, but I get:
Traceback (most recent call last):
File "gluon-mnist-v5.py", line 145, in
loss = softmax_cross_entropy(output, label)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/block.py", line 290, in __call__
return self.forward(*args)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/block.py", line 474, in forward
return self.hybrid_forward(ndarray, x, *args, **params)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/loss.py", line 314, in hybrid_forward
loss = -F.pick(pred, label, axis=self._axis, keepdims=True)
File "", line 76, in pick
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke
ctypes.byref(out_stypes)))
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/base.py", line 146, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Shape inconsistent, Provided=(64,), inferred shape=(128,)
but then when a define “net.add(Prlu(64))” and I get:
Traceback (most recent call last):
File "gluon-mnist-v5.py", line 144, in
output = net(data)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/block.py", line 290, in __call__
return self.forward(*args)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/nn/basic_layers.py", line 50, in forward
x = block(x)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/block.py", line 290, in __call__
return self.forward(*args)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/block.py", line 474, in forward
return self.hybrid_forward(ndarray, x, *args, **params)
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/gluon/nn/basic_layers.py", line 201, in hybrid_forward
flatten=self._flatten, name='fwd')
File "", line 74, in FullyConnected
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke
ctypes.byref(out_stypes)))
File "/Users/bc/mxnet/lib/python3.6/site-packages/mxnet/base.py", line 146, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Shape inconsistent, Provided=(10,8192), inferred shape=(10,4096)