File size: 910 Bytes
8aa674c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from mmengine.registry import Registry

EVALUATORS = Registry("evaluators")


def build_evaluator(cfg):
    """Build evaluator."""
    return EVALUATORS.build(cfg)


def remove_duplicate_annotations(ants, tol=1e-3):
    # remove duplicate annotations (same category and starting/ending time)
    valid_events = []
    for event in ants:
        s, e, l = event["segment"][0], event["segment"][1], event["label"]
        # here, we add removing the events whose duration is 0, (HACS)
        if e - s <= 0:
            continue
        valid = True
        for p_event in valid_events:
            if (
                (abs(s - p_event["segment"][0]) <= tol)
                and (abs(e - p_event["segment"][1]) <= tol)
                and (l == p_event["label"])
            ):
                valid = False
                break
        if valid:
            valid_events.append(event)
    return valid_events