I am new to MXNet and want to solve a simple example that uses 1 layer network to solve the digit classification problem. My program goes as follows:
import math
import numpy as np
import mxnet as mx
import matplotlib.pyplot as plt
import logging
logging.getLogger().setLevel(logging.DEBUG)
#============================================================
with np.load("notMNIST.npz") as data:
images, labels = data["images"], data["labels"]
# Reshape the images from 28x28 into 784 1D-array and flaten the labels.
images = images.reshape(784, 18720) labels = labels.reshape(18720)
# Apply one-hot encoding.
Images = images.T.astype(np.float32)
Labels = np.zeros((18720, 10)).astype(np.float32)
Labels[np.arange(18720), labels] = 1
# Segment the data into training, evaluation and testing.
X_train = Images[0 : 15000]
y_train = Labels[0 : 15000]
X_eval = Images[15000 : 16000]
y_eval = Labels[ 1200 : 2200] # IMPORTANT!!!
X_test = Images[16000 : 18720]
y_test = Labels[16000 : 18720]
train_iter = mx.io.NDArrayIter(X_train, y_train, 100, shuffle=False)
_eval_iter = mx.io.NDArrayIter(X_eval , y_eval , 100, shuffle=False)
#============================================================
# Variables
X = mx.sym.Variable(name='data')
# Neural Network Layers
fully_connected_layer = mx.sym.FullyConnected(data=X, name='fc1', num_hidden=10)
# Outputs
lro = mx.sym.SoftmaxOutput(data=fully_connected_layer, name="softmax")
#============================================================
model = mx.mod.Module(symbol=lro)
model.fit(train_data=train_iter, eval_data=_eval_iter,
optimizer='sgd', optimizer_params={
'learning_rate' : 1e-5,
'momentum' : 0.1},
eval_metric="acc",
num_epoch=500)
After running the program with evaluation label 15000
to 16000
, the final step is reporting a validation accuracy of 97%
, which I personally argue is too high for a 1-layer network. Therefore, I deliberately changed the evaluation labels to 1200
to 2200
and saw that the program is still reporting an accuracy at around 83~86%
(at first I thought that maybe it is just a coincidence and tried several different evaluation labels but still got similar results).
What mistakes have I made in my program?