Commit e244fe88 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Add the script used to create psuedo identities

parent 76941036
Pipeline #25009 failed with stage
in 53 seconds
# coding: utf-8
from bob.bio.base.score.load import load_score, dump_score
from bob.fusion.base.tools.common import (
get_2negatives_1positive, get_score_lines)
import numpy as np
def average_scores(scores_path):
new_lines = []
with open(scores_path) as f:
old_lines = f.readlines()
old_lines.sort()
for i, line in enumerate(old_lines):
uniq, s = line.strip().rsplit(maxsplit=1)
if i == 0:
last_line = uniq
last_scores = []
if uniq == last_line:
last_scores.append(float(s))
else:
new_lines.append('{} {}\n'.format(last_line, np.mean(last_scores)))
last_scores = []
last_line = uniq
else:
new_lines.append('{} {}\n'.format(last_line, np.mean(last_scores)))
with open(scores_path, 'w') as f:
f.writelines(new_lines)
def intersection_of_scores(path1, path2):
def set_of_uniqs(lines):
a = set()
for line in lines:
uniq, s = line.strip().rsplit(maxsplit=1)
a.add(uniq)
return a
with open(path1) as f1, open(path2) as f2:
lines1, lines2 = f1.readlines(), f2.readlines()
lines1.sort(), lines2.sort()
set1, set2 = set_of_uniqs(lines1), set_of_uniqs(lines2)
final_set = set1.intersection(set2)
def write_lines_set(f, lines, fin_set):
for line in lines:
uniq, s = line.strip().rsplit(maxsplit=1)
if uniq in fin_set:
f.write(line)
with open(path1, 'w') as f1, open(path2, 'w') as f2:
write_lines_set(f1, lines1, final_set)
write_lines_set(f2, lines2, final_set)
def normalize_scores(face_scores_path, finger_scores_path):
face_scores = load_score(face_scores_path)
finger_scores = load_score(finger_scores_path)
finger_scores = get_score_lines([finger_scores,
face_scores])[:len(finger_scores)]
face_gen, face_zei = get_2negatives_1positive(face_scores)[:2]
finger_gen, finger_zei = get_2negatives_1positive(finger_scores)[:2]
finger_ids = np.unique(finger_scores['real_id'])
face_ids = np.unique(face_scores['real_id'])
id_map = {pid: fid for fid, pid in zip(face_ids, finger_ids)}
sample_map = {}
for pid, fid in id_map.items():
fsamples = list(
dict.fromkeys(face_gen[face_gen['real_id'] == fid]['test_label']))
psamples = list(
dict.fromkeys(
finger_gen[finger_gen['real_id'] == pid]['test_label']))
sample_map.update({p: f for p, f in zip(psamples, fsamples)})
def drop_samples(scores, ids, samples):
ids, samples = list(ids), list(samples)
m1 = np.in1d(scores['claimed_id'], ids)
m2 = np.in1d(scores['real_id'], ids)
m3 = np.in1d(scores['test_label'], samples)
return scores[m1 & m2 & m3]
face_gen = drop_samples(face_gen, id_map.values(), sample_map.values())
face_zei = drop_samples(face_zei, id_map.values(), sample_map.values())
finger_gen = drop_samples(finger_gen, id_map.keys(), sample_map.keys())
finger_zei = drop_samples(finger_zei, id_map.keys(), sample_map.keys())
face_scores = get_score_lines([face_gen], [face_zei])
finger_scores = get_score_lines([finger_gen], [finger_zei])
# replace values in finger scores
for line in finger_scores:
line['real_id'] = id_map[line['real_id']]
line['claimed_id'] = id_map[line['claimed_id']]
line['test_label'] = sample_map[line['test_label']]
dump_score(face_scores_path + '-new', face_scores)
dump_score(finger_scores_path + '-new', finger_scores)
average_scores(finger_scores_path + '-new')
intersection_of_scores(finger_scores_path + '-new',
face_scores_path + '-new')
for modality in ['face', 'voice']:
for grp in ['dev', 'eval']:
normalize_scores(
'scores/multi-modal/{}/scores-{}'.format(modality, grp),
'scores/multi-modal/fingerprint/scores-{}'.format(grp))
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