1

I am trying to understand the Handwritten Digit recognition for MXNet in python here

The code which creates the training data and label data is shown below:

def read_data(label_url, image_url):
    with gzip.open(download_data(label_url)) as flbl:
        magic, num = struct.unpack(">II", flbl.read(8))
        label = np.fromstring(flbl.read(), dtype=np.int8)
    with gzip.open(download_data(image_url), 'rb') as fimg:
        magic, num, rows, cols = struct.unpack(">IIII", fimg.read(16))
        image = np.fromstring(fimg.read(), dtype=np.uint8).reshape(len(label), rows, cols)
    return (label, image)

Then the numbers are predicted using the code below:

prob = model.predict(val_img[0:1].astype(np.float32)/255)[0]
assert max(prob) > 0.99, "Low prediction accuracy."
print 'Classified as %d with probability %f' % (prob.argmax(), max(prob))

The output is - Classified as 7 with probability 0.999391. My question is how MXNet was able to determine that the index returned by argmax function corresponds to label -7

Abhishek Kishore
  • 340
  • 2
  • 13

1 Answers1

0

The value 7 is coming from prob.argmax(). That method returns the index of the top scoring value.

https://mxnet.incubator.apache.org/api/python/ndarray.html#mxnet.ndarray.argmax