You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for the Accuracy function in cnn_ocr.py. def Accuracy(label, pred): label = label.T.reshape((-1, )) hit = 0 total = 0 for i in range(pred.shape[0] / 5): ok = True for j in range(5): k = i * 5 + j if np.argmax(pred[k]) != int(label[k]): ok = False break if ok: hit += 1 total += 1 return 1.0 * hit / total
I notice that the shape of output from model is (batch_size*label_num,softmax_num); and the ground truth label shape is (batch_size,softmax_num). So I just thought the label at [k] after label.T.reshape((-1, )) is not coressponding to np.argmax(pred[k]). I do think it should be:
def Accuracy2(label, pred): # made by me label = label hit = 0 total = 0 for i in range(pred.shape[0] / 5): ok = True for j in range(4): k = i * 4 + j if np.argmax(pred[k]) != int(label[i, j]): ok = False break if ok: hit += 1 total += 1 return 1.0 * hit / total
Am I wrong?
The text was updated successfully, but these errors were encountered:
for the Accuracy function in cnn_ocr.py.
def Accuracy(label, pred): label = label.T.reshape((-1, )) hit = 0 total = 0 for i in range(pred.shape[0] / 5): ok = True for j in range(5): k = i * 5 + j if np.argmax(pred[k]) != int(label[k]): ok = False break if ok: hit += 1 total += 1 return 1.0 * hit / total
I notice that the shape of output from model is (batch_size*label_num,softmax_num); and the ground truth label shape is (batch_size,softmax_num). So I just thought the label at [k] after label.T.reshape((-1, )) is not coressponding to np.argmax(pred[k]). I do think it should be:
def Accuracy2(label, pred): # made by me label = label hit = 0 total = 0 for i in range(pred.shape[0] / 5): ok = True for j in range(4): k = i * 4 + j if np.argmax(pred[k]) != int(label[i, j]): ok = False break if ok: hit += 1 total += 1 return 1.0 * hit / total
Am I wrong?
The text was updated successfully, but these errors were encountered: