Commit 976ff53a authored by Sulfyderz's avatar Sulfyderz
Browse files

[New]:Adding the PurityCoverage method in diar_tools.

parent 7ec2d1c4
......@@ -8,6 +8,7 @@ import collections
import numpy as np
import pandas as pd
import pyannote.metrics.segmentation as pyaseg
import pyannote.metrics.diarization as pyadiar
import pyannote.core as pyacore
from s4d.scoring import DER
from s4d.diar import Diar, Segment
......@@ -1705,7 +1706,7 @@ def firstIntervention(diar,cluster):
## cluster: Cluster name given for a segment absence
def FRFA(diarHyp,diarRef,diarUem=None,tolerance=25,cluster="fillFRFA"):
assert isinstance(cluster,str) and (diarUem is None or isinstance(diarUem,Diar)) and isinstance(diarHyp,Diar) and isinstance(diarRef,Diar) and isinstance(tolerance,numbers.Number)
tolerance=tolerance/100
tolerance=(tolerance/100)*2
diarHyp=copy.deepcopy(diarHyp)
diarRef=copy.deepcopy(diarRef)
segPre=pyaseg.SegmentationPrecision(tolerance)
......@@ -1951,6 +1952,36 @@ def projectBoundaries(diar,diarSource):
outputDiar.sort()
return outputDiar
# Returns a dict object representing the Purity and the Coverage
## tolerance: In centiseconds
## skip_overlap: Computing according to overlap or not
def PurityCoverage(diarHyp,diarRef,diarUem=None,tolerance=25,skip_overlap=False):
assert isinstance(skip_overlap,bool) and (diarUem is None or isinstance(diarUem,Diar)) and isinstance(diarHyp,Diar) and isinstance(diarRef,Diar) and isinstance(tolerance,numbers.Number)
tolerance=(tolerance/100)*2
reference = pyacore.Annotation()
for seg in diarRef:
s = pyacore.Segment(seg['start'], seg['stop'])
if s not in reference:
reference[s, 1] = seg['cluster']
else:
reference[s, 2] = seg['cluster']
ref_uem = pyacore.Timeline()
for seg in diarUem:
ref_uem.add(pyacore.Segment(seg['start'], seg['stop']))
hyp = pyacore.Annotation()
for seg in diarHyp:
hyp[pyacore.Segment(seg['start'], seg['stop'])] = seg['cluster']
p=pyadiar.DiarizationPurity(collar=tolerance,skip_overlap=skip_overlap)
c=pyadiar.DiarizationCoverage(collar=tolerance,skip_overlap=skip_overlap)
rtn=dict()
rtn["Purity"]=p.compute_metric(p.compute_components(reference,hyp,ref_uem))*100
rtn["Cover"]=c.compute_metric(c.compute_components(reference,hyp,ref_uem))*100
return rtn
# Reads any file according the extension
def read(fn):
if isinstance(fn,str):
......
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