2017-02-28 55 views
1

我想了解MXNet的手寫漢字識別在Python here如何在MXNet

它創建的訓練數據和標籤數據如下所示的代碼確定標籤的指標:

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) 

然後,數字用下面的代碼預測:

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)) 

的輸出 - 被分類爲7的概率爲0.999391。 我的問題是MXNet如何能夠確定由argmax函數返回的索引對應於標籤-7

回答