Commit 2bfef0d8 authored by Sushil Bhattacharjee's avatar Sushil Bhattacharjee

speaker-lab files

parent 2a6f834c
Pipeline #24270 failed with stage
in 1 minute and 10 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
#############
#
# Plotting utilities
#
#############
import bob.io.image
import bob.io.base
import matplotlib.pyplot as pyplot
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import colors as mcolors
import bob.measure
import bob.measure.load
import os
def plot_with_subplots(image_a, image_b):
"""
Plot two images side by side with matplotlib subplot
and set special titles for it
**Parameters**
image_a:
image_b:
"""
if image_a.ndim == 3:
cmap=None
else:
cmap='gray'
figure = pyplot.figure(figsize=(16,8))
pyplot.subplot(121)
pyplot.axis('off')
pyplot.title('enroll')
pyplot.imshow(bob.io.image.to_matplotlib(image_a), cmap=cmap)
pyplot.subplot(122)
pyplot.axis('off')
pyplot.title('probe')
pyplot.imshow(bob.io.image.to_matplotlib(image_b), cmap=cmap)
pyplot.show()
def plot_with_subplots_list(images):
"""
Plot a list of images in subplots
**Parameters**
images: list
List of loaded images
"""
figure = pyplot.figure(figsize=(8,4))
for i,im in enumerate(images):
if im.ndim == 3:
cmap=None
else:
cmap='gray'
pyplot.subplot(1,len(images),i+1)
pyplot.axis('off')
pyplot.imshow(bob.io.image.to_matplotlib(im), cmap=cmap)
pyplot.show()
def plot_hist(zero_effort_scores, genuine_scores, fmr_01=None, fmr_001=None):
"""
Plot histogram distribution
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
"""
bins = 100
figure = pyplot.figure(figsize=(16,8))
pyplot.suptitle("Score distribution")
if fmr_01 is None:
fmr_01 = bob.measure.far_threshold(zero_effort_scores, genuine_scores, 0.1)
if fmr_001 is None:
fmr_001 = bob.measure.far_threshold(zero_effort_scores, genuine_scores, 0.01)
# DEV
pyplot.hist(zero_effort_scores, color="C0", bins=bins, alpha=0.8, label="Zero-effort impostors", density=True)
pyplot.hist(genuine_scores, color="C2", bins=bins, alpha=0.9, label="Genuines", density=True)
pyplot.axvline(x=fmr_01, color="red", linestyle="dashed", label="FMR=0.1")
pyplot.axvline(x=fmr_001, color="orange", linestyle="dashed", label="FMR=0.01")
pyplot.legend(ncol=1, bbox_to_anchor=(0.7, 1.1))
pyplot.show()
return fmr_01, fmr_001
def plot_roc(zero_effort_scores, genuine_scores):
"""
Plot ROC curve
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
"""
# ROC curve
pyplot.figure(figsize=(16,8))
bob.measure.plot.roc(zero_effort_scores, genuine_scores, npoints=100, CAR=True)
pyplot.grid(True)
pyplot.title("Receiver Operating Characteristic (ROC) curve")
pyplot.xlabel("FMR")
pyplot.ylabel("100 - FNMR")
#pyplot.ylim((0,1.))
pyplot.show()
def plot_det(zero_effort_scores, genuine_scores):
"""
Plot DET curve
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
"""
pyplot.figure(figsize=(16, 8))
bob.measure.plot.det(zero_effort_scores, genuine_scores, npoints=100)
bob.measure.plot.det_axis([0.01, 99, 0.01, 99])
pyplot.grid(True)
pyplot.title("Detection Error Tradeoff (DET)")
pyplot.xlabel("FMR(%)")
pyplot.ylabel("FNMR(%)")
pyplot.show()
def compute_fnmrs(zero_effort_scores, genuine_scores, one_minus=True):
"""
Compute the False Non Match Rate at FMR 0.1 and 0.01
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
one_minus: bool
one_minus = True returns 1-FNMR
"""
_,frr_01 = bob.measure.farfrr(zero_effort_scores, genuine_scores, bob.measure.far_threshold(zero_effort_scores, genuine_scores, 0.1))
_,frr_001 = bob.measure.farfrr(zero_effort_scores, genuine_scores, bob.measure.far_threshold(zero_effort_scores, genuine_scores, 0.01))
if one_minus:
return round(1-frr_01,2)*100, round(1-frr_001, 2)*100
else:
return round(frr_01, 2)*100, round(frr_001, 2)*100
def plot_multiroc(file_names, labels, base_path="./scores"):
"""
Plot ROC curves from several systems
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
"""
# ROC curve
pyplot.figure(figsize=(16,8))
for f, l in zip(file_names, labels):
zero_effort_scores, genuine_scores = bob.measure.load.split(os.path.join(base_path, f))
bob.measure.plot.roc(zero_effort_scores, genuine_scores, npoints=100, CAR=True, label=l)
pyplot.grid(True)
pyplot.title("Receiver Operating Characteristic (ROC) curve")
pyplot.xlabel("FMR")
pyplot.ylabel("100 - FNMR")
#pyplot.ylim((0,1.))
pyplot.legend()
pyplot.show()
def plot_multidet(file_names, labels, base_path="./scores"):
"""
Plot DET curves from several systems
**Parameters**
zero_effort_scores: numpy.array
Zeroth effort impostor scores
genuine_scores: numpy.array
Genuine scores
"""
# ROC curve
pyplot.figure(figsize=(16,8))
for f, l in zip(file_names, labels):
zero_effort_scores, genuine_scores = bob.measure.load.split(os.path.join(base_path, f))
bob.measure.plot.det(zero_effort_scores, genuine_scores, npoints=100, label=l)
bob.measure.plot.det_axis([0.01, 99, 0.01, 99])
pyplot.grid(True)
pyplot.title("Detection Error Tradeoff (DET)")
pyplot.xlabel("FMR(%)")
pyplot.ylabel("FNMR(%)")
pyplot.legend()
pyplot.show()
from pathlib import Path
import bob.bio.gmm
import numpy
# we assume that the file is in the 4-column format devised for bob-score-files.
def load_scores(score_filename):
my_file = Path(score_filename)
assert my_file.is_file(), "File %s does not exist. Quitting." %score_filename
dsf = open(score_filename, "r")
x = dsf.readlines()
dsf.close()
gen_scores = [float(line.split()[3]) for line in x if line.split()[0] == line.split()[1]]
zei_scores = [float(line.split()[3]) for line in x if line.split()[0] != line.split()[1]]
return numpy.array(zei_scores), numpy.array(gen_scores)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment