code: def calculate_roc(
      thresholds,
      embeddings1,
      embeddings2,
      actual_issame,
      nrof_folds=10,
      pca=0,
  ):
      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)
  
      tprs = np.zeros((nrof_folds, nrof_thresholds))
      fprs = np.zeros((nrof_folds, nrof_thresholds))
      accuracy = np.zeros((nrof_folds))
      indices = np.arange(nrof_pairs)
      # print('pca', pca)
  
      if pca == 0:
          diff = np.subtract(embeddings1, embeddings2)
          dist = np.sum(np.square(diff), 1)
  
      for fold_idx, (train_set, test_set) in enumerate(
          k_fold.split(indices)
      ):
          # print('train_set', train_set)
          # print('test_set', test_set)
          if pca > 0:
              print("doing pca on", fold_idx)
              embed1_train = embeddings1[train_set]
              embed2_train = embeddings2[train_set]
              _embed_train = np.concatenate(
                  (embed1_train, embed2_train), axis=0
              )
              # print(_embed_train.shape)
              pca_model = PCA(n_components=pca)
              pca_model.fit(_embed_train)
              embed1 = pca_model.transform(embeddings1)
              embed2 = pca_model.transform(embeddings2)
              embed1 = sklearn.preprocessing.normalize(embed1)
              embed2 = sklearn.preprocessing.normalize(embed2)
              # print(embed1.shape, embed2.shape)
              diff = np.subtract(embed1, embed2)
              dist = np.sum(np.square(diff), 1)
  
          # Find the best threshold for the fold
          acc_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)
          # print('threshold', thresholds[best_threshold_index])
          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, accuracy
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import argparse
  import sys
  import numpy
  from scipy import misc
  from sklearn.model_selection import KFold
  from scipy import interpolate
  import sklearn
  import cv2
  import math
  import datetime
  import pickle
  from sklearn.decomposition import PCA
  import mxnet
  from mxnet import ndarray
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_roc(thresholds, embeddings1, embeddings2, actual_issame, nrof_folds, pca) and returns: tpr,  fpr,  accuracy