facenet
facenet copied to clipboard
evaluate function in training step will raise error : "float division by zero"
Take new pairs of pics as the evaluate dataset, raise error "float division by zero" in calculate_val_far function (facenet.py).
the codes in function "calculate_val_far"(508L @ facenet.py) is :
def calculate_val_far(threshold, dist, actual_issame):
predict_issame = np.less(dist, threshold)
true_accept = np.sum(np.logical_and(predict_issame, actual_issame))
false_accept = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame)))
n_same = np.sum(actual_issame)
n_diff = np.sum(np.logical_not(actual_issame))
val = float(true_accept) / float(n_same)
far = float(false_accept) / float(n_diff)
return val, far
BUT! When the all samples in one floder are positive sample, and the "actual_issame" in function will be all "True", which causes the "n_diff" will be zero! It is same to the "n_same" when all samples are neg.
So, may change to
def calculate_val_far(threshold, dist, actual_issame):
predict_issame = np.less(dist, threshold)
true_accept = np.sum(np.logical_and(predict_issame, actual_issame))
false_accept = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame)))
n_same = np.sum(actual_issame)
n_diff = np.sum(np.logical_not(actual_issame))
val = float(true_accept) / float(n_same) if float(n_same) > 0 else 1.0
far = float(false_accept) / float(n_diff) if float(n_diff) > 0 else 0.0
return val, far
When you generate pairs.txt file in this file you have mixture of similar match and dissimilar match are present randomly. so at the time of batch formation both the type of data present (similar and dissimilar)
with an unbalanced evaluation dataset ( not the lfw dataset ), with k-flod(491L @ facenet.py), may all similar match or all dissimilar match.
Use an exception handler in def calculate_var_far()
in facenet.py
for the values
- val
- far