FAR和FRR評價函式

2021-09-09 06:46:59 字數 3880 閱讀 6866

1.frr:錯誤拒接率(false reject rate)。

文字定義:錯誤拒絕率,把同乙個人的對當成不同的人對的概率。

其中:errorcount是指匹配失敗的次數,totalcount是指同乙個人的匹配次數。

也就是說,假設我們定義匹配的時候設定的閾值為threshold,當兩兩匹配的時候的相似度值為value。

在理想情況下,同乙個人的匹配相似度value>threshold總是成立的。在現實中,當valuethreshold的時候,這就是匹配失敗。

**實現:

import numpy as np

import os

from time import time

from sklearn import svm

from sklearn.multiclass import onevsrestclassifier

from sklearn.tree import decisiontreeclassifier

from sklearn.metrics import roc_curve, auc

from sklearn.linear_model import linearregression

from sklearn.pipeline import pipeline

from skimage import io

from string import digits

from pil import image

from sklearn.model_selection import train_test_split

from matplotlib import pyplot as plt

from scipy import interp

import matplotlib.pyplot as plt

import pandas as pd

import keras

from sklearn.utils import shuffle

def train_model(model,x_train,y_train,x_test,y_test):

model.fit(x_train, y_train,

batch_size=10,

epochs=1,

validation_data=(x_test,y_test),

shuffle=true)

return model

def compute_cv_cnn(model,x_train,y_train,x_test,y_test):

scores =

model = train_model(model,x_train, y_train,x_test,y_test)

predictions = model.predict_proba(x_test);

scores = np.array(scores)

mean = np.mean(scores, axis=0)

return mean

def unison_shuffled_copies(a, b):

assert len(a) == len(b)

p = np.random.permutation(len(a))

return a[p], b[p]

array_np = np.copy(arr)

low_val_indices = arr < treshold

high_val_indices = arr >= treshold

array_np[low_val_indices] = 0

array_np[high_val_indices] = 1

return array_np

def perf_measure(actual, score, treshold):

tp = 0

fp = 0

tn = 0

fn = 0

size = len(score)

for i in range(size):

for j in range(len(score[i])):

if(predarr[j] != actual[i][j] and predarr[j] == 1):

fp+=1

if(predarr[j] == actual[i][j] == 1):

tp+=1

if(predarr[j] != actual[i][j] and predarr[j] == 0):

fn+=1

if(predarr[j] == actual[i][j] == 0):

tn+=1

print("tp%d,fp%d,tn%d,fn%d"%(tp,fp,tn,fn))

return tp, fp, tn, fn

def calc_far_frr(fp, fn,totalp, totaln):

far = fp/float(totalp) # totalpfalse accept rate in percentage

frr = fn/float(totaln) # false reject rate in percentage

return far, frr

def prepare_graph_far_frr(actual, score, totalp, totaln):

step = 1

far = dict()

frr = dict()

for i in range(0, 100, step):

tp, fp, tn, fn = perf_measure(actual, score, i/float(100))

far[i], frr[i] = calc_far_frr(fp, fn, totalp, totaln)

return far, frr

def plot_far_frr(far, frr):

axisval = np.arange(0,1.00,0.01);

# plot far frr

plt.figure(1)

lw = 2

plt.plot(far.values(), axisval, label='false accept rate', color='blue', lw=lw)

plt.plot(axisval, frr.values(), label='false reject rate', color='red', lw=lw)

# plt.grid(ls='--')

plt.xlim([0.0, 1.0])

plt.ylim([0.0, 1.05])

plt.xlabel('treshold')

plt.ylabel('errors')

plt.title('far and frr')

plt.legend(loc="lower right")

far =

frr =

for key,value in far.items():

for key,value in frr.items():

far = np.array(far)

frr = np.array(frr)

residue = np.abs(far-frr)

residue = residue.tolist()

min_index = residue.index(min(residue))

eer = (far[min_index]+frr[min_index])*50

print("eer is %.2f%%"%(eer))

Tenengrad評價函式

tenengrad函式式一種常用的影象清晰度評價函式,是一種基於梯度的函式。在影象處理中,一般認為對焦好的影象具有更尖銳的邊緣,故具有更大的梯度函式值。tenengrad函式使用sobel運算元提取水平和垂直方向的梯度值。具體過程如下 設sobel卷積核為 定義該影象的tenengrad值為 其中實...

量化評價和質化評價舉例 量化評價和質性評價異同點

量化評價和質性評價在理論上有分歧,但它們不是兩種對立的方法,在課程評價中是非常必要和不可缺少的。它們的分歧能在課程評價實踐中統一起來,互相彌補各自的缺點。1.量化評價的特點 量化評價的優點是邏輯性強,標準化和精確化程度較高,能對課程現象的因果關係作出精確分析,結論也更為客觀和科學。然而,影響制約教育...

損失函式與評價函式

4.1 學習目標 掌握常見的評價函式和損失函式dice iou bce focal loss lov sz softmax 掌握評價 損失函式的實踐 4.2 tp tn fp fn 在講解語義分割中常用的評價函式和損失函式之前,先補充一 tp 真正例 true positive tn 真反例 tru...