My code is Below
train_iter = mx.io.NDArrayIter(data = train_x, label = train_y, batch_size = 128, shuffle = True)
inputs = sym.Variable(‘data’)
targets = sym.Variable(‘softmax_label’)
w1 = sym.Variable(‘w1’, shape = (784, 256), init = mx.init.Xavier())
b1 = sym.Variable(‘b1’, shape = (256,), init = mx.init.Zero())
w2 = sym.Variable(‘w2’, shape = (256, 128), init = mx.init.Xavier())
b2 = sym.Variable(‘b2’, shape = (128,), init = mx.init.Zero())
w3 = sym.Variable(‘w3’, shape = (128, 10), init = mx.init.Xavier())
b3 = sym.Variable(‘b3’, shape = (10), init = mx.init.Zero())
layer1 = sym.relu(sym.broadcast_add(sym.dot(inputs, w1), b1))
layer2 = sym.relu(sym.broadcast_add(sym.dot(layer1, w2), b2))
predictions = sym.softmax(sym.broadcast_add(sym.dot(layer2, w3), b3))
cost = sym.MakeLoss(sym.sum(-targets * sym.log(predictions)))
model = mx.mod.Module(cost)
model.fit(train_iter, optimizer = ‘adam’, optimizer_params={‘learning_rate’:0.1}, num_epoch=10)
when I run model.fit its throws error:-
Check failed: axis < ndim && axis >= -ndim axis 1 exceeds the input dimension of 1
the shape of train_y and train_y (which are used to create iterator) is (60000, 784) and (60000, 10) respectively.
plz help me i have been trying different methods but none of them worked
Complete Error is below
MXNetError Traceback (most recent call last)
in
2 optimizer=‘adam’,
3 optimizer_params={‘learning_rate’:0.1},
----> 4 num_epoch=10)
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\module\base_module.py in fit(self, train_data, eval_data, eval_metric, epoch_end_callback, batch_end_callback, kvstore, optimizer, optimizer_params, eval_end_callback, eval_batch_end_callback, initializer, arg_params, aux_params, allow_missing, force_rebind, force_init, begin_epoch, num_epoch, validation_metric, monitor, sparse_row_id_fn)
531 pre_sliced=True)
532 else:
–> 533 self.update_metric(eval_metric, data_batch.label)
534
535 try:
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\module\module.py in update_metric(self, eval_metric, labels, pre_sliced)
771 Whether the labels are already sliced per device (default: False).
772 “”"
–> 773 self._exec_group.update_metric(eval_metric, labels, pre_sliced)
774
775 def _sync_params_from_devices(self):
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\module\executor_group.py in update_metric(self, eval_metric, labels, pre_sliced)
637 labels_ = OrderedDict(zip(self.label_names, labels_slice))
638 preds = OrderedDict(zip(self.output_names, texec.outputs))
–> 639 eval_metric.update_dict(labels_, preds)
640
641 def _bind_ith_exec(self, i, data_shapes, label_shapes, shared_group):
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\metric.py in update_dict(self, label, pred)
130 label = list(label.values())
131
–> 132 self.update(label, pred)
133
134 def update(self, labels, preds):
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\metric.py in update(self, labels, preds)
416 if pred_label.shape != label.shape:
417 pred_label = ndarray.argmax(pred_label, axis=self.axis)
–> 418 pred_label = pred_label.asnumpy().astype(‘int32’)
419 label = label.asnumpy().astype(‘int32’)
420 # flatten before checking shapes to avoid shape miss match
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\ndarray\ndarray.py in asnumpy(self)
1970 self.handle,
1971 data.ctypes.data_as(ctypes.c_void_p),
-> 1972 ctypes.c_size_t(data.size)))
1973 return data
1974
c:\users\rishik\appdata\local\programs\python\python36\lib\site-packages\mxnet\base.py in check_call(ret)
249 “”"
250 if ret != 0:
–> 251 raise MXNetError(py_str(_LIB.MXGetLastError()))
252
253
MXNetError: [11:59:39] c:\jenkins\workspace\mxnet-tag\mxnet\src\operator\nn…/tensor/broadcast_reduce_op.h:151: Check failed: axis < ndim && axis >= -ndim axis 1 exceeds the input dimension of 1