def evaluate(sess, enqueue_op, image_paths_placeholder, labels_placeholder, phase_train_placeholder, batch_size_placeholder, control_placeholder, embeddings, labels, image_paths, actual_issame, batch_size, nrof_folds, log_dir, step, summary_writer, stat, epoch, distance_metric, subtract_mean, use_flipped_images, use_fixed_image_standardization):
    start_time = time.time()
    print('Runnning forward pass on LFW images')
    nrof_embeddings = (len(actual_issame) * 2)
    nrof_flips = (2 if use_flipped_images else 1)
    nrof_images = (nrof_embeddings * nrof_flips)
    labels_array = np.expand_dims(np.arange(0, nrof_images), 1)
    image_paths_array = np.expand_dims(np.repeat(np.array(image_paths), nrof_flips), 1)
    control_array = np.zeros_like(labels_array, np.int32)
    if use_fixed_image_standardization:
        control_array += (np.ones_like(labels_array) * facenet.FIXED_STANDARDIZATION)
    if use_flipped_images:
        control_array += ((labels_array % 2) * facenet.FLIP)
    sess.run(enqueue_op, {image_paths_placeholder: image_paths_array, labels_placeholder: labels_array, control_placeholder: control_array})
    embedding_size = int(embeddings.get_shape()[1])
    assert ((nrof_images % batch_size) == 0), 'The number of LFW images must be an integer multiple of the LFW batch size'
    nrof_batches = (nrof_images // batch_size)
    emb_array = np.zeros((nrof_images, embedding_size))
    lab_array = np.zeros((nrof_images,))
    for i in range(nrof_batches):
        feed_dict = {phase_train_placeholder: False, batch_size_placeholder: batch_size}
        (emb, lab) = sess.run([embeddings, labels], feed_dict=feed_dict)
        lab_array[lab] = lab
        emb_array[lab, :] = emb
        if ((i % 10) == 9):
            print('.', end='')
            sys.stdout.flush()
    print('')
    embeddings = np.zeros((nrof_embeddings, (embedding_size * nrof_flips)))
    if use_flipped_images:
        embeddings[:, :embedding_size] = emb_array[0::2, :]
        embeddings[:, embedding_size:] = emb_array[1::2, :]
    else:
        embeddings = emb_array
    assert (np.array_equal(lab_array, np.arange(nrof_images)) == True), 'Wrong labels used for evaluation, possibly caused by training examples left in the input pipeline'
    (_, _, accuracy, val2, val_std2, far2, val3, val_std3, far3) = lfw.evaluate(embeddings, actual_issame, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)
    print(('Accuracy: %1.3f+-%1.3f' % (np.mean(accuracy), np.std(accuracy))))
    print(('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val2, val_std2, far2)))
    print(('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val3, val_std3, far3)))
    lfw_time = (time.time() - start_time)
    summary = tf.Summary()
    summary.value.add(tag='lfw/accuracy', simple_value=np.mean(accuracy))
    summary.value.add(tag='lfw/val_rate2', simple_value=val2)
    summary.value.add(tag='lfw/val_rate3', simple_value=val3)
    summary.value.add(tag='time/lfw', simple_value=lfw_time)
    summary_writer.add_summary(summary, step)
    with open(os.path.join(log_dir, 'lfw_result.txt'), 'at') as f:
        f.write(('%d\t%.5f\t%.5f\t%.5f\n' % (step, np.mean(accuracy), val2, val3)))
    stat['lfw_accuracy'][(epoch - 1)] = np.mean(accuracy)
    stat['lfw_valrate2'][(epoch - 1)] = val2
    stat['lfw_valrate3'][(epoch - 1)] = val3
def evaluate(sess, enqueue_op, image_paths_placeholder, labels_placeholder, phase_train_placeholder, batch_size_placeholder, control_placeholder, embeddings, labels, image_paths, actual_issame, batch_size, nrof_folds, log_dir, step, summary_writer, stat, epoch, distance_metric, subtract_mean, use_flipped_images, use_fixed_image_standardization):
    start_time = time.time()
    print('Runnning forward pass on LFW images')
    nrof_embeddings = (len(actual_issame) * 2)
    nrof_flips = (2 if use_flipped_images else 1)
    nrof_images = (nrof_embeddings * nrof_flips)
    labels_array = np.expand_dims(np.arange(0, nrof_images), 1)
    image_paths_array = np.expand_dims(np.repeat(np.array(image_paths), nrof_flips), 1)
    control_array = np.zeros_like(labels_array, np.int32)
    if use_fixed_image_standardization:
        control_array += (np.ones_like(labels_array) * facenet.FIXED_STANDARDIZATION)
    if use_flipped_images:
        control_array += ((labels_array % 2) * facenet.FLIP)
    sess.run(enqueue_op, {image_paths_placeholder: image_paths_array, labels_placeholder: labels_array, control_placeholder: control_array})
    embedding_size = int(embeddings.get_shape()[1])
    assert ((nrof_images % batch_size) == 0), 'The number of LFW images must be an integer multiple of the LFW batch size'
    nrof_batches = (nrof_images // batch_size)
    emb_array = np.zeros((nrof_images, embedding_size))
    lab_array = np.zeros((nrof_images,))
    for i in range(nrof_batches):
        feed_dict = {phase_train_placeholder: False, batch_size_placeholder: batch_size}
        (emb, lab) = sess.run([embeddings, labels], feed_dict=feed_dict)
        lab_array[lab] = lab
        emb_array[lab, :] = emb
        if ((i % 10) == 9):
            print('.', end=)
            sys.stdout.flush()
    print()
    embeddings = np.zeros((nrof_embeddings, (embedding_size * nrof_flips)))
    if use_flipped_images:
        embeddings[:, :embedding_size] = emb_array[0::2, :]
        embeddings[:, embedding_size:] = emb_array[1::2, :]
    else:
        embeddings = emb_array
    assert (np.array_equal(lab_array, np.arange(nrof_images)) == True), 'Wrong labels used for evaluation, possibly caused by training examples left in the input pipeline'
    (_, _, accuracy, val2, val_std2, far2, val3, val_std3, far3) = lfw.evaluate(embeddings, actual_issame, nrof_folds=nrof_folds, distance_metric=distance_metric, subtract_mean=subtract_mean)
    print(('Accuracy: %1.3f+-%1.3f' % (np.mean(accuracy), np.std(accuracy))))
    print(('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val2, val_std2, far2)))
    print(('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val3, val_std3, far3)))
    lfw_time = (time.time() - start_time)
    summary = tf.Summary()
    summary.value.add(tag='lfw/accuracy', simple_value=np.mean(accuracy))
    summary.value.add(tag='lfw/val_rate2', simple_value=val2)
    summary.value.add(tag='lfw/val_rate3', simple_value=val3)
    summary.value.add(tag='time/lfw', simple_value=lfw_time)
    summary_writer.add_summary(summary, step)
    with open(os.path.join(log_dir, 'lfw_result.txt'), 'at') as f:
        f.write(('%d\t%.5f\t%.5f\t%.5f\n' % (step, np.mean(accuracy), val2, val3)))
    stat['lfw_accuracy'][(epoch - 1)] = np.mean(accuracy)
    stat['lfw_valrate2'][(epoch - 1)] = val2
    stat['lfw_valrate3'][(epoch - 1)] = val3