Commit feb18807 authored by Hugo Fougeres's avatar Hugo Fougeres
Browse files

commit

parents
Copyright (c) 2021-present NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
AASIST
Copyright (c) 2021-present NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---
This project contains subcomponents with separate copyright notices and license terms.
Your use of the source code for these subcomponents is subject to the terms and conditions of the following licenses.
=====================================================================================================================
asvspoof-challenge/2021/LA/Baseline-RawNet2
https://github.com/asvspoof-challenge/2021/tree/main/LA/Baseline-RawNet2
MIT License
Copyright (c) 2021 eurecom-asp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=====
Jungjee/RawNet
https://github.com/Jungjee/RawNet
MIT License
Copyright (c) 2021 Jee-weon Jung
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=====
min t-DCF implementation for ASVspoof2019
https://www.asvspoof.org/resources/tDCF_python_v2.zip
A Python code package for computing t-DCF and EER metrics for ASVspoof2019.
(Version 2.0)
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International
License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/
or send a letter to
Creative Commons, 444 Castro Street, Suite 900,
Mountain View, California, 94041, USA.
=====
# AASIST
This repository provides the overall framework for training and evaluating audio anti-spoofing systems proposed in ['AASIST: Audio Anti-Spoofing using Integrated Spectro-Temporal Graph Attention Networks'](https://arxiv.org/abs/2110.01200)
### Getting started
`requirements.txt` must be installed for execution. We state our experiment environment for those who prefer to simulate as similar as possible.
- Installing dependencies
```
pip install -r requirements.txt
```
- Our environment (for GPU training)
- Based on a docker image: `pytorch:1.6.0-cuda10.1-cudnn7-runtime`
- GPU: 1 NVIDIA Tesla V100
- About 16GB is required to train AASIST using a batch size of 24
- gpu-driver: 418.67
### Data preparation
We train/validate/evaluate AASIST using the ASVspoof 2019 logical access dataset [4].
```
python ./download_dataset.py
```
(Alternative) Manual preparation is available via
- ASVspoof2019 dataset: https://datashare.ed.ac.uk/handle/10283/3336
1. Download `LA.zip` and unzip it
2. Set your dataset directory in the configuration file
### Training
The `main.py` includes train/validation/evaluation.
To train AASIST [1]:
```
python main.py --config ./config/AASIST.conf
```
To train AASIST-L [1]:
```
python main.py --config ./config/AASIST-L.conf
```
#### Training baselines
We additionally enabled the training of RawNet2[2] and RawGAT-ST[3].
To Train RawNet2 [2]:
```
python main.py --config ./config/RawNet2_baseline.conf
```
To train RawGAT-ST [3]:
```
python main.py --config ./config/RawGATST_baseline.conf
```
### Pre-trained models
We provide pre-trained AASIST and AASIST-L.
To evaluate AASIST [1]:
- It shows `EER: 0.83%`, `min t-DCF: 0.0275`
```
python main.py --eval --config ./config/AASIST.conf
```
To evaluate AASIST-L [1]:
- It shows `EER: 0.99%`, `min t-DCF: 0.0309`
- Model has `85,306` parameters
```
python main.py --eval --config ./config/AASIST-L.conf
```
### Developing custom models
Simply by adding a configuration file and a model architecture, one can train and evaluate their models.
To train a custom model:
```
1. Define your model
- The model should be a class named "Model"
2. Make a configuration by modifying "model_config"
- architecture: filename of your model.
- hyper-parameters to be tuned can be also passed using variables in "model_config"
3. run python main.py --config {CUSTOM_CONFIG_NAME}
```
### License
```
Copyright (c) 2021-present NAVER Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
### Acknowledgements
This repository is built on top of several open source projects.
- [ASVspoof 2021 baseline repo](https://github.com/asvspoof-challenge/2021/tree/main/LA/Baseline-RawNet2)
- [min t-DCF implementation](https://www.asvspoof.org/resources/tDCF_python_v2.zip)
The repository for baseline RawGAT-ST model will be open
- https://github.com/eurecom-asp/RawGAT-ST-antispoofing
The dataset we use is ASVspoof 2019 [4]
- https://www.asvspoof.org/index2019.html
### References
[1] AASIST: Audio Anti-Spoofing using Integrated Spectro-Temporal Graph Attention Networks
```bibtex
@INPROCEEDINGS{Jung2021AASIST,
author={Jung, Jee-weon and Heo, Hee-Soo and Tak, Hemlata and Shim, Hye-jin and Chung, Joon Son and Lee, Bong-Jin and Yu, Ha-Jin and Evans, Nicholas},
booktitle={arXiv preprint arXiv:2110.01200},
title={AASIST: Audio Anti-Spoofing using Integrated Spectro-Temporal Graph Attention Networks},
year={2021}
```
[2] End-to-End anti-spoofing with RawNet2
```bibtex
@INPROCEEDINGS{Tak2021End,
author={Tak, Hemlata and Patino, Jose and Todisco, Massimiliano and Nautsch, Andreas and Evans, Nicholas and Larcher, Anthony},
booktitle={Proc. ICASSP},
title={End-to-End anti-spoofing with RawNet2},
year={2021},
pages={6369-6373}
}
```
[3] End-to-end spectro-temporal graph attention networks for speaker verification anti-spoofing and speech deepfake detection
```bibtex
@inproceedings{tak21_asvspoof,
author={Tak, Hemlata and Jung, Jee-weon and Patino, Jose and Kamble, Madhu and Todisco, Massimiliano and Evans, Nicholas},
booktitle={Proc. ASVSpoof Challenge},
title={End-to-end spectro-temporal graph attention networks for speaker verification anti-spoofing and speech deepfake detection},
year={2021},
pages={1--8}
```
[4] ASVspoof 2019: A large-scale public database of synthesized, converted and replayed speech
```bibtex
@article{wang2020asvspoof,
title={ASVspoof 2019: A large-scale public database of synthesized, converted and replayed speech},
author={Wang, Xin and Yamagishi, Junichi and Todisco, Massimiliano and Delgado, H{\'e}ctor and Nautsch, Andreas and Evans, Nicholas and Sahidullah, Md and Vestman, Ville and Kinnunen, Tomi and Lee, Kong Aik and others},
journal={Computer Speech \& Language},
volume={64},
pages={101114},
year={2020},
publisher={Elsevier}
}
```
import os
import numpy as np
import evaluation as em
import matplotlib.pyplot as plt
def compute_eer_and_tdcf(scorefile, namefile):
asv_score_file = os.path.join('config/LA/ASVspoof2019_LA_asv_scores/ASVspoof2019.LA.asv.eval.gi.trl.scores.txt')
cm_score_file = os.path.join('eval_scores_using_best_dev_model.txt')
# Fix tandem detection cost function (t-DCF) parameters
Pspoof = 0.05
cost_model = {
'Pspoof': Pspoof, # Prior probability of a spoofing attack
'Ptar': (1 - Pspoof) * 0.99, # Prior probability of target speaker
'Pnon': (1 - Pspoof) * 0.01, # Prior probability of nontarget speaker
'Cmiss_asv': 1, # Cost of ASV system falsely rejecting target speaker
'Cfa_asv': 10, # Cost of ASV system falsely accepting nontarget speaker
'Cmiss_cm': 1, # Cost of CM system falsely rejecting target speaker
'Cfa_cm': 10, # Cost of CM system falsely accepting spoof
}
# Load organizers' ASV scores
asv_data = np.genfromtxt(asv_score_file, dtype=str)
asv_sources = asv_data[:, 0]
asv_keys = asv_data[:, 1]
asv_scores = asv_data[:, 2].astype(np.float)
# Load CM scores
cm_data = np.genfromtxt(cm_score_file, dtype=str)
cm_utt_id = cm_data[:, 0]
cm_sources = cm_data[:, 1]
cm_keys = cm_data[:, 2]
cm_scores = cm_data[:, 3].astype(np.float)
other_cm_scores = -cm_scores
# Extract target, nontarget, and spoof scores from the ASV scores
tar_asv = asv_scores[asv_keys == 'target']
non_asv = asv_scores[asv_keys == 'nontarget']
spoof_asv = asv_scores[asv_keys == 'spoof']
# Extract bona fide (real human) and spoof scores from the CM scores
bona_cm = cm_scores[cm_keys == 'bonafide']
spoof_cm = cm_scores[cm_keys == 'spoof']
# EERs of the standalone systems and fix ASV operating point to EER threshold
eer_asv, asv_threshold = em.compute_eer(tar_asv, non_asv)
eer_cm = em.compute_eer(bona_cm, spoof_cm)[0]
other_eer_cm = em.compute_eer(other_cm_scores[cm_keys == 'bonafide'], other_cm_scores[cm_keys == 'spoof'])[0]
[Pfa_asv, Pmiss_asv, Pmiss_spoof_asv] = em.obtain_asv_error_rates(tar_asv, non_asv, spoof_asv, asv_threshold)
if eer_cm < other_eer_cm:
# Compute t-DCF
tDCF_curve, CM_thresholds = em.compute_tDCF(bona_cm, spoof_cm, Pfa_asv, Pmiss_asv, Pmiss_spoof_asv, cost_model, True)
# Minimum t-DCF
min_tDCF_index = np.argmin(tDCF_curve)
min_tDCF = tDCF_curve[min_tDCF_index]
else:
tDCF_curve, CM_thresholds = em.compute_tDCF(other_cm_scores[cm_keys == 'bonafide'], other_cm_scores[cm_keys == 'spoof'],
Pfa_asv, Pmiss_asv, Pmiss_spoof_asv, cost_model, True)
# Minimum t-DCF
min_tDCF_index = np.argmin(tDCF_curve)
min_tDCF = tDCF_curve[min_tDCF_index]
# print('ASV SYSTEM')
# print(' EER = {:8.5f} % (Equal error rate (target vs. nontarget discrimination)'.format(eer_asv * 100))
# print(' Pfa = {:8.5f} % (False acceptance rate of nontargets)'.format(Pfa_asv * 100))
# print(' Pmiss = {:8.5f} % (False rejection rate of targets)'.format(Pmiss_asv * 100))
# print(' 1-Pmiss,spoof = {:8.5f} % (Spoof false acceptance rate)'.format((1 - Pmiss_spoof_asv) * 100))
# Visualize ASV scores and CM scores
plt.figure()
#ax = plt.subplot(121)
#plt.hist(tar_asv, histtype='step', density=True, bins=50, label='Target')
#plt.hist(non_asv, histtype='step', density=True, bins=50, label='Nontarget')
#plt.hist(spoof_asv, histtype='step', density=True, bins=50, label='Spoof')
#plt.plot(asv_threshold, 0, 'o', markersize=10, mfc='none', mew=2, clip_on=False, label='EER threshold')
#plt.legend()
#plt.xlabel('ASV score')
#plt.ylabel('Density')
#plt.title('ASV score histogram')
#ax = plt.subplot(122)
plt.hist(bona_cm, histtype='step', density=True, bins=50, label='Bona fide curve')
plt.hist(spoof_cm, histtype='step', density=True, bins=50, label='Spoof curve')
plt.plot(scorefile, 0, 'o', markersize=10, mfc='none', mew=2, clip_on=False, label='Score of the audio')
plt.axvline(scorefile, linestyle='dotted')
plt.plot(0.027529478, 0, 'o', markersize=10, mfc='none', mew=2, clip_on=False, label='Min TDCF')
plt.legend()
plt.xlabel('CM score')
plt.ylabel('Density')
plt.title('Result of the scoring')
plt.savefig('./public/results.png')
plt.savefig('./public/results/{}-{}.png'.format(namefile, scorefile))
return min(eer_cm, other_eer_cm), min_tDCF
\ No newline at end of file
import numpy as np
import soundfile as sf
import torch
from torch import Tensor
from torch.utils.data import Dataset
___author__ = "Hemlata Tak, Jee-weon Jung"
__email__ = "tak@eurecom.fr, jeeweon.jung@navercorp.com"
def genSpoof_list(dir_meta, is_train=False, is_eval=False):
d_meta = {}
file_list = []
with open(dir_meta, "r") as f:
l_meta = f.readlines()
if is_train:
for line in l_meta:
_, key, _, _, label = line.strip().split(" ")
file_list.append(key)
d_meta[key] = 1 if label == "bonafide" else 0
return d_meta, file_list
elif is_eval:
for line in l_meta:
_, key, _, _, _ = line.strip().split(" ")
#key = line.strip()
file_list.append(key)
return file_list
else:
for line in l_meta:
_, key, _, _, label = line.strip().split(" ")
file_list.append(key)
d_meta[key] = 1 if label == "bonafide" else 0
return d_meta, file_list
def pad(x, max_len=64600):
x_len = x.shape[0]
if x_len >= max_len:
return x[:max_len]
# need to pad
num_repeats = int(max_len / x_len) + 1
padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0]
return padded_x
def pad_random(x: np.ndarray, max_len: int = 64600):
x_len = x.shape[0]
# if duration is already long enough
if x_len >= max_len:
stt = np.random.randint(x_len - max_len)
return x[stt:stt + max_len]
# if too short
num_repeats = int(max_len / x_len) + 1
padded_x = np.tile(x, (num_repeats))[:max_len]
return padded_x
class Dataset_ASVspoof2019_train(Dataset):
def __init__(self, list_IDs, labels, base_dir):
"""self.list_IDs : list of strings (each string: utt key),
self.labels : dictionary (key: utt key, value: label integer)"""
self.list_IDs = list_IDs
self.labels = labels
self.base_dir = base_dir
self.cut = 64600 # take ~4 sec audio (64600 samples)
def __len__(self):
return len(self.list_IDs)
def __getitem__(self, index):
key = self.list_IDs[index]
#X, _ = sf.read(str(self.base_dir / f"flac/{key}.flac"))
#X, _ = sf.read(str(self.base_dir /'flac/'+key+'.flac'))
X, _ = sf.read(str("config/LA/ASVspoof2019_LA_train/flac/"+key+'.flac'))
X_pad = pad_random(X, self.cut)
x_inp = Tensor(X_pad)
y = self.labels[key]
return x_inp, y
class Dataset_ASVspoof2019_devNeval(Dataset):
def __init__(self, list_IDs, base_dir):
"""self.list_IDs : list of strings (each string: utt key),
"""
self.list_IDs = list_IDs
self.base_dir = base_dir
self.cut = 64600 # take ~4 sec audio (64600 samples)
def __len__(self):
return len(self.list_IDs)
def __getitem__(self, index):
key = self.list_IDs[index]
X, _ = sf.read(str("config/LA/ASVspoof2019_LA_eval/flac/"+key+'.flac'))
X_pad = pad(X, self.cut)
x_inp = Tensor(X_pad)
return x_inp, key
class Dataset_ASVspoof2019_devNeval_all(Dataset):
def __init__(self, list_IDs, base_dir):
"""self.list_IDs : list of strings (each string: utt key),
"""
self.list_IDs = list_IDs
self.base_dir = base_dir
self.cut = 64600 # take ~4 sec audio (64600 samples)
def __len__(self):
return len(self.list_IDs)
def __getitem__(self, index):
key = self.list_IDs[index]
X, _ = sf.read(str("config/LA/ASVspoof2019_LA_eval/flac/"+key+'.flac'))
X_pad = pad(X, self.cut)
x_inp = Tensor(X_pad)
return x_inp, key
\ No newline at end of file
"""
AASIST
Copyright (c) 2021-present NAVER Corp.
MIT license
"""
import os
if __name__ == "__main__":
cmd = "curl -o ./LA.zip -# https://datashare.ed.ac.uk/bitstream/handle/10283/3336/LA.zip\?sequence\=3\&isAllowed\=y"
os.system(cmd)
cmd = "unzip LA.zip"
os.system(cmd)
\ No newline at end of file
This diff is collapsed.
import sys
import os
import numpy as np
def calculate_tDCF_EER(cm_scores_file,
asv_score_file,
output_file,
printout=True):
# Replace CM scores with your own scores or provide score file as the
# first argument.
# cm_scores_file = 'score_cm.txt'
# Replace ASV scores with organizers' scores or provide score file as
# the second argument.
# asv_score_file = 'ASVspoof2019.LA.asv.eval.gi.trl.scores.txt'
# Fix tandem detection cost function (t-DCF) parameters
Pspoof = 0.05
cost_model = {
'Pspoof': Pspoof, # Prior probability of a spoofing attack
'Ptar': (1 - Pspoof) * 0.99, # Prior probability of target speaker
'Pnon': (1 - Pspoof) * 0.01, # Prior probability of nontarget speaker
'Cmiss': 1, # Cost of ASV system falsely rejecting target speaker
'Cfa': 10, # Cost of ASV system falsely accepting nontarget speaker
'Cmiss_asv': 1, # Cost of ASV system falsely rejecting target speaker
'Cfa_asv':
10, # Cost of ASV system falsely accepting nontarget speaker
'Cmiss_cm': 1, # Cost of CM system falsely rejecting target speaker
'Cfa_cm': 10, # Cost of CM system falsely accepting spoof
}
# Load organizers' ASV scores
asv_data = np.genfromtxt(asv_score_file, dtype=str)
# asv_sources = asv_data[:, 0]
asv_keys = asv_data[:, 1]
asv_scores = asv_data[:, 2].astype(np.float)
# Load CM scores
#cm_data=np.array([[],[]])
cm_data = np.genfromtxt('exp_result/LA_AASIST_ep100_bs24/eval_scores_using_best_dev_model.txt', dtype=str)
# cm_utt_id = cm_data[:, 0]
cm_sources = cm_data[:, 1]
#print (cm_sources)
cm_keys = cm_data[:, 2]
cm_scores = cm_data[:, 3].astype(np.float)
# Extract target, nontarget, and spoof scores from the ASV scores
tar_asv = asv_scores[asv_keys == 'target']
non_asv = asv_scores[asv_keys == 'nontarget']
spoof_asv = asv_scores[asv_keys == 'spoof']
# Extract bona fide (real human) and spoof scores from the CM scores
bona_cm = cm_scores[cm_keys == 'bonafide']
spoof_cm = cm_scores[cm_keys == 'spoof']
# EERs of the standalone systems and fix ASV operating point to
# EER threshold
eer_asv, asv_threshold = compute_eer(tar_asv, non_asv)
eer_cm = compute_eer(bona_cm, spoof_cm)[0]
attack_types = [f'A{_id:02d}' for _id in range(7, 20)]
if printout:
spoof_cm_breakdown = {
attack_type: cm_scores[cm_sources == attack_type]
for attack_type in attack_types
}
eer_cm_breakdown = {
attack_type: compute_eer(bona_cm,
spoof_cm_breakdown[attack_type])[0]
for attack_type in attack_types
}
[Pfa_asv, Pmiss_asv,
Pmiss_spoof_asv] = obtain_asv_error_rates(tar_asv, non_asv, spoof_asv,
asv_threshold)
# Compute t-DCF
tDCF_curve, CM_thresholds = compute_tDCF(bona_cm,
spoof_cm,
Pfa_asv,
Pmiss_asv,
Pmiss_spoof_asv,
cost_model,
print_cost=False)
# Minimum t-DCF
min_tDCF_index = np.argmin(tDCF_curve)
min_tDCF = tDCF_curve[min_tDCF_index]
if printout:
with open(output_file, "w") as f_res:
f_res.write('\nCM SYSTEM\n')
f_res.write('\tEER\t\t= {:8.9f} % '
'(Equal error rate for countermeasure)\n'.format(
eer_cm * 100))
f_res.write('\nTANDEM\n')
f_res.write('\tmin-tDCF\t\t= {:8.9f}\n'.format(min_tDCF))
f_res.write('\nBREAKDOWN CM SYSTEM\n')
for attack_type in attack_types:
_eer = eer_cm_breakdown[attack_type] * 100
f_res.write(
f'\tEER {attack_type}\t\t= {_eer:8.9f} % (Equal error rate for {attack_type}\n'
)
os.system(f"cat {output_file}")
return eer_cm * 100, min_tDCF