Exemple #1
0
def evaluate(embeddings, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)
    thresholds = np.arange(0, 4, 0.001)
    val2, val_std2, far2 = facenet.calculate_val(thresholds, embeddings1, embeddings2, np.asarray(actual_issame), 1e-2, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)
    val3, val_std3, far3 = facenet.calculate_val(thresholds, embeddings1, embeddings2, np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)
    
    return tpr, fpr, accuracy, val2, val_std2, far2, val3, val_std3, far3
Exemple #2
0
def evaluate(embeddings,
             actual_issame,
             nrof_folds=10,
             distance_metric=0,
             subtract_mean=False,
             labels=None,
             logdir=None):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds,
                                               embeddings1,
                                               embeddings2,
                                               np.asarray(actual_issame),
                                               nrof_folds=nrof_folds,
                                               distance_metric=distance_metric,
                                               subtract_mean=subtract_mean,
                                               labels=labels,
                                               logdir=logdir)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds,
                                              embeddings1,
                                              embeddings2,
                                              np.asarray(actual_issame),
                                              1e-3,
                                              nrof_folds=nrof_folds,
                                              distance_metric=distance_metric,
                                              subtract_mean=subtract_mean)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #3
0
def evaluate(embeddings, actual_issame, nrof_folds=10, distance_metric=0):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    if distance_metric == 1:
        thresholds = np.arange(0, 1, 0.001)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds,
                                               embeddings1,
                                               embeddings2,
                                               np.asarray(actual_issame),
                                               nrof_folds=nrof_folds,
                                               distance_metric=distance_metric)
    thresholds = np.arange(0, 4, 0.001)
    if distance_metric == 1:
        thresholds = np.arange(0, 1, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds,
                                              embeddings1,
                                              embeddings2,
                                              np.asarray(actual_issame),
                                              1e-3,
                                              nrof_folds=nrof_folds,
                                              distance_metric=distance_metric)
    f1 = 2 * np.mean(accuracy) * val / (np.mean(accuracy) + val)
    return tpr, fpr, accuracy, val, val_std, far, f1
Exemple #4
0
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    # tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
    #     np.asarray(actual_issame), nrof_folds=nrof_folds)
    # thresholds = np.arange(0, 4, 0.001)
    # val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
    #     np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds)

    tpr, fpr, accuracy, fp_idx, fn_idx, best_threshold_acc = facenet.calculate_roc(
        thresholds,
        embeddings1,
        embeddings2,
        np.asarray(actual_issame),
        nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far, threshold_val = facenet.calculate_val(
        thresholds,
        embeddings1,
        embeddings2,
        np.asarray(actual_issame),
        1e-3,
        nrof_folds=nrof_folds)

    return tpr, fpr, accuracy, val, val_std, far, fp_idx, fn_idx, best_threshold_acc, threshold_val
Exemple #5
0
def validate(sess, paths, actual_issame, seed, batch_size, images_placeholder, phase_train_placeholder, embeddings, nrof_folds=10):

    image_size = images_placeholder.get_shape()[1]
    
    # Run forward pass to calculate embeddings
    print('Runnning forward pass on LFW images')
    nrof_images = len(paths)
    nrof_batches = int(math.ceil(1.0*nrof_images / batch_size))
    emb_list = []
    for i in range(nrof_batches):
        start_index = i*batch_size
        end_index = min((i+1)*batch_size, nrof_images)
        paths_batch = paths[start_index:end_index]
        images = facenet.load_data(paths_batch, False, False, image_size)
        feed_dict = { images_placeholder: images, phase_train_placeholder: False }
        emb_list += sess.run([embeddings], feed_dict=feed_dict)
    emb_array = np.vstack(emb_list)  # Stack the embeddings to a nrof_examples_per_epoch x 128 matrix

    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = emb_array[0::2]
    embeddings2 = emb_array[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), seed, nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, seed, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #6
0
def validate(sess, paths, actual_issame, seed, batch_size, images_placeholder, phase_train_placeholder, embeddings, nrof_folds=10):

    image_size = images_placeholder.get_shape()[1]
    
    # Run forward pass to calculate embeddings
    print('Runnning forward pass on LFW images')
    nrof_images = len(paths)
    nrof_batches = int(math.ceil(1.0*nrof_images / batch_size))
    emb_list = []
    for i in range(nrof_batches):
        start_index = i*batch_size
        end_index = min((i+1)*batch_size, nrof_images)
        paths_batch = paths[start_index:end_index]
        images = facenet.load_data(paths_batch, False, False, image_size)
        feed_dict = { images_placeholder: images, phase_train_placeholder: False }
        emb_list += sess.run([embeddings], feed_dict=feed_dict)
    emb_array = np.vstack(emb_list)  # Stack the embeddings to a nrof_examples_per_epoch x 128 matrix

    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = emb_array[0::2]
    embeddings2 = emb_array[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), seed, nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, seed, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #8
0
def evaluate(embeddings, seed, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), seed, nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, seed, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #9
0
def evaluate(embeddings, actual_issame, nrof_folds=10, distance_metric=0, subtract_mean=False):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)          #用来判定TP,FP的阈值,从0-4,0.01间隔,交叉验证,可以得出最优的threadhold
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]

    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)

    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)

    return tpr, fpr, accuracy, val, val_std, far
Exemple #10
0
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)  # 0.01表示步长
    # 四个点原来是取奇数和偶数列
    embeddings1 = embeddings[0::2]  # 取出奇数行的特征,取出偶数行的特征
    embeddings2 = embeddings[1::2]
    # print(len(embeddings1))
    # print('wokao')
    # print(len(embeddings2))
    tpr, fpr, accuracy, threshold_acc = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
                                                              np.asarray(actual_issame),
                                                              nrof_folds=nrof_folds)  # np.asarray将列表转换为数组
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds, threshold_acc, embeddings1, embeddings2,
                                              np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #11
0
def main(argv=None):
  
    pairs = read_pairs(os.path.expanduser(FLAGS.lfw_pairs))
    paths, actual_issame = get_paths(os.path.expanduser(FLAGS.lfw_dir), pairs)
    
    with tf.Graph().as_default():

        with tf.Session() as sess:
            
            # Load the model
            print('Loading model "%s"' % FLAGS.model_file)
            facenet.load_model(FLAGS.model_file)
            
            # Get input and output tensors
            images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
            phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
            embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
            image_size = images_placeholder.get_shape()[1]
            
            # Run forward pass to calculate embeddings
            nrof_images = len(paths)
            nrof_batches = int(nrof_images / FLAGS.batch_size)
            emb_list = []
            for i in range(nrof_batches):
                start_time = time.time()
                paths_batch = paths[i*FLAGS.batch_size:(i+1)*FLAGS.batch_size]
                images = facenet.load_data(paths_batch, False, False, image_size)
                feed_dict = { images_placeholder: images, phase_train_placeholder: False }
                emb_list += sess.run([embeddings], feed_dict=feed_dict)
                duration = time.time() - start_time
                print('Calculated embeddings for batch %d of %d: time=%.3f seconds' % (i+1,nrof_batches, duration))
            emb_array = np.vstack(emb_list)  # Stack the embeddings to a nrof_examples_per_epoch x 128 matrix

            # Calculate evaluation metrics
            thresholds = np.arange(0, 4, 0.01)
            embeddings1 = emb_array[0::2]
            embeddings2 = emb_array[1::2]
            tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2, np.asarray(actual_issame), FLAGS.seed)
            print('Accuracy: %1.3f+-%1.3f' % (np.mean(accuracy), np.std(accuracy)))
            thresholds = np.arange(0, 4, 0.001)
            val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2, np.asarray(actual_issame), 1e-3, FLAGS.seed)
            print('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val, val_std, far))
            facenet.plot_roc(fpr, tpr, 'NN4')
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    # Note there that x[startAt:endBefore:skip] is the notation
    # so embeddings1 and embeddings2 are simply two lists with
    # embeddings1[i] and embeddings2[i] being the pairs that we need to validate    
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    print("thresholds is: {}".format(thresholds))
    print("embeddings1 is: {}".format(embeddings1))
    print("embeddings2 is: {}".format(embeddings2))
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    # val is the percentage of samples that were classified to be correct
    # val_std is the std of val
    # far is the percentage of samples that were classified to be wrong
    val, val_std, far = facenet.calculate_val(thresholds, embeddings1, embeddings2,
        np.asarray(actual_issame), 1e-3, nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
Exemple #13
0
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    # start from 0, step=2
    embeddings1 = embeddings[0::2]
    # start from 1, step=2
    embeddings2 = embeddings[1::2]
    # embeddings1 is corresponding with embeddings2
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds,
                                               embeddings1,
                                               embeddings2,
                                               np.asarray(actual_issame),
                                               nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds,
                                              embeddings1,
                                              embeddings2,
                                              np.asarray(actual_issame),
                                              1e-3,
                                              nrof_folds=nrof_folds)
    return tpr, fpr, accuracy, val, val_std, far
def evaluate(embeddings, actual_issame, nrof_folds=10):
    # Calculate evaluation metrics
    thresholds = np.arange(0, 4, 0.01)
    embeddings1 = embeddings[0::2]
    embeddings2 = embeddings[1::2]
    # ipdb.set_trace()
    tpr, fpr, accuracy = facenet.calculate_roc(thresholds,
                                               embeddings1,
                                               embeddings2,
                                               np.asarray(actual_issame),
                                               nrof_folds=nrof_folds)
    thresholds = np.arange(0, 4, 0.001)
    val, val_std, far = facenet.calculate_val(thresholds,
                                              embeddings1,
                                              embeddings2,
                                              np.asarray(actual_issame),
                                              1e-2,
                                              nrof_folds=nrof_folds)
    dot_product_threshold = np.arange(0.0, 1.0, 0.001)
    # ipdb.set_trace()
    best_threshold, acc_dot, recall, fpr_dot, precision_dot,  dot_product_all, fp_idxs, fn_idxs, recall_th, precision_th,\
    acc_th = facenet.calculate_acc_dot_product(dot_product_threshold, embeddings1, embeddings2, np.asarray(actual_issame))
    return tpr, fpr, accuracy, val, val_std, far, best_threshold, acc_dot, recall, fpr_dot, precision_dot,\
           dot_product_all, fp_idxs, fn_idxs, recall_th, precision_th, acc_th