lfw数据验证
LFW數(shù)據(jù)驗(yàn)證
以facenet的lfw數(shù)據(jù)驗(yàn)證為例 lfw數(shù)據(jù)地址:http://vis-www.cs.umass.edu/lfw/ lfw數(shù)據(jù):
- 13233 images
- 5749 people
- 1680 people with two or more images
驗(yàn)證數(shù)據(jù)分兩個,一個用于開發(fā),一個用于最終的驗(yàn)證
這里驗(yàn)證使用的是View 2的pairs.txt文件
training, validation, and testing
? ?View 1: development training/testing sets
? ?View 2: performance testing configurations
? ?pairs.txt file format
? ?people.txt file format
1.mean classification accuracy
def calculate_roc(thresholds, embeddings1, embeddings2, actual_issame, 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 = KFold(n_splits=nrof_folds, shuffle=False)tprs = np.zeros((nrof_folds,nrof_thresholds))fprs = np.zeros((nrof_folds,nrof_thresholds))accuracy = 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 best threshold for the foldacc_train = np.zeros((nrof_thresholds))for threshold_idx, threshold in enumerate(thresholds):_, _, acc_train[threshold_idx] = calculate_accuracy(threshold, dist[train_set], actual_issame[train_set])best_threshold_index = np.argmax(acc_train)for threshold_idx, threshold in enumerate(thresholds):tprs[fold_idx,threshold_idx], fprs[fold_idx,threshold_idx], _ = calculate_accuracy(threshold, dist[test_set], actual_issame[test_set])_, _, accuracy[fold_idx] = calculate_accuracy(thresholds[best_threshold_index], dist[test_set], actual_issame[test_set])tpr = np.mean(tprs,0)fpr = np.mean(fprs,0)return tpr, fpr, accuracydef calculate_accuracy(threshold, dist, actual_issame):predict_issame = np.less(dist, threshold)tp = np.sum(np.logical_and(predict_issame, actual_issame))fp = np.sum(np.logical_and(predict_issame, np.logical_not(actual_issame)))tn = np.sum(np.logical_and(np.logical_not(predict_issame), np.logical_not(actual_issame)))fn = np.sum(np.logical_and(np.logical_not(predict_issame), actual_issame))tpr = 0 if (tp+fn==0) else float(tp) / float(tp+fn)fpr = 0 if (fp+tn==0) else float(fp) / float(fp+tn)acc = float(tp+tn)/dist.sizereturn tpr, fpr, acc
這里的accuracy是使用pairs.txt中的人臉對進(jìn)行10交叉驗(yàn)證得到的平均準(zhǔn)確率2.roc
thresholds = np.arange(0, 4, 0.01) tpr和fpr分別對應(yīng)交叉驗(yàn)證的平均tpr和平均fpr總結(jié)
- 上一篇: 一个服务器多个网站多个域名,多个域名一个
- 下一篇: linux 双mipi摄像头,VS-RK