Coming from Keras, I try to reproduce my simple model with MXNet to make prediction using Module.
I'm using that simple dataset: https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data
I've got 13 inputs (from alcohol to Proline) that I want to send to the model, and I need to classify the first column that is "wine type", so I create a nd.array that have 3 entries.
x = data.values[: , 1:14]
y = data.values[:, 0]
X = mx.nd.array(x)
Y = []
for i, v in enumerate(y):
d = [0,0,0]
d[int(v)-1] = 1
Y.append(d)
Y = mx.nd.array(Y)
Y.shape, X.shape
# ((178, 3), (178, 13))
Then I create the model and a NDIterator:
net = mx.symbol.Variable('winechemical')
net = mx.symbol.FullyConnected(net, num_hidden=64)
net = mx.symbol.Activation(net, act_type='relu')
net = mx.symbol.FullyConnected(net, num_hidden=32)
net = mx.symbol.Activation(net, act_type='relu')
net = mx.symbol.FullyConnected(net, num_hidden=16)
net = mx.symbol.SoftmaxOutput(net, name='wineclass')
model = Module(symbol=net, context=mx.cpu(),
data_names=['winechemical'],
label_names=['wineclass_label'])
gen = mx.io.NDArrayIter(X, label=Y,
batch_size=10,
shuffle=True, data_name='winechemical',
label_name='wineclass_label')
But when I try to "train" the model using the "fit" method, I got this error:
model.fit(gen, num_epoch=5) [...] Error in operator wineclass: Shape inconsistent, Provided = [10,3], inferred shape=[10]
I'm pretty sure that I don't understand the shape to uses as I'm coming from Keras that use different shape... But where am I wrong ?
Thanks for your help.