we can see the following function。
def calculate_val(thresholds, embeddings1, embeddings2, actual_issame, far_target, nrof_folds=10):
assert(embeddings1.shape[0] == embeddings2.shape[0])
assert(embeddings1.shape[1] == embeddings2.shape[1])
nrof_pairs = min(len(actual_issame), embeddings1.shape[0])
nrof_thresholds = len(thresholds)
k_fold = LFold(n_splits=nrof_folds, shuffle=False)
val = np.zeros(nrof_folds)
far = np.zeros(nrof_folds)
diff = np.subtract(embeddings1, embeddings2)
dist = np.sum(np.square(diff),1)
indices = np.arange(nrof_pairs)
for fold_idx, (train_set, test_set) in enumerate(k_fold.split(indices)):
# Find the threshold that gives FAR = far_target
far_train = np.zeros(nrof_thresholds)
for threshold_idx, threshold in enumerate(thresholds):
_, far_train[threshold_idx] = calculate_val_far(threshold, dist[train_set], actual_issame[train_set])
if np.max(far_train)>=far_target:
f = interpolate.interp1d(far_train, thresholds, kind='slinear')
threshold = f(far_target)
else:
threshold = 0.0
val[fold_idx], far[fold_idx] = calculate_val_far(threshold, dist[test_set], actual_issame[test_set])
val_mean = np.mean(val)
far_mean = np.mean(far)
val_std = np.std(val)
return val_mean, val_std, far_mean
waiting for your reply!
As we just need a threshold
i don't understand what's your meaning.
but the cosine distance will get the better acc on lfw than euclidean metric ? and because our loss is based the angle,so i think the cosine distance is more appropriate.
sphereface 's github use cosine distance.
waiting for your reply!
the feature has been normalized, so euclidean metric actually plays equal to cos distance
||A-B||^2 = ||A||^2+||B||^2-2*dot(A,B) = 2-2 cos(A,B) if ||A||^2 = 1 & ||B||^2 = 1 for A,B belongs to R^n
great
thanks very much
this can be closed
Most helpful comment
||A-B||^2 = ||A||^2+||B||^2-2*dot(A,B) = 2-2 cos(A,B) if ||A||^2 = 1 & ||B||^2 = 1 for A,B belongs to R^n