I am new to mxnet, I am trying to do this code:
from mxnet import nd, sym
from mxnet.gluon import nn
class HybridNet(nn.HybridBlock):
def __init__(self, **kwargs):
super(HybridNet, self).__init__(**kwargs)
self.hidden = nn.Dense(10)
self.output = nn.Dense(2)
def hybrid_forward(self, F, x):
print('F: ', F)
print('x: ', x.shape)
x = F.relu(self.hidden(x))
print('hidden: ', x.shape)
x = F.relu(self.hidden(x))
print('hidden: ', x.shape)
return self.output(x)
net = HybridNet()
net.initialize()
x = nd.random.normal(shape=(1, 4))
net(x)
however, it got this error: MXNetError: Shape inconsistent, Provided = [10,4], inferred shape=(10,10)
but if I change self.hidden = nn.Dense(10) to self.hidden = nn.Dense(4), the error would not exist any more. but I cannot understand why, anyone could explain this to me? thank you