File size: 2,722 Bytes
6efeebe
 
 
 
 
d9015be
6efeebe
 
 
 
 
 
 
 
 
 
 
 
 
d9015be
6efeebe
 
 
 
 
 
d9015be
 
 
 
 
 
 
6efeebe
d9015be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6efeebe
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import json
import os
from pathlib import Path
import sys

pwd = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(pwd, "../../"))

from tqdm import tqdm


def get_args():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "--eval_file",
        # default=r"native_silero_vad.jsonl",
        type=str
    )
    args = parser.parse_args()
    return args


evaluation_files = [
    "native_silero_vad.jsonl",
    "fsmn-vad.jsonl",
    "silero-vad.jsonl"
]


def main():
    # args = get_args()

    for eval_file in evaluation_files:
        eval_file = Path(eval_file)
        total = 0
        total_duration = 0
        total_accuracy = 0
        total_precision = 0
        total_recall = 0
        total_f1 = 0

        average_accuracy = 0
        average_precision = 0
        average_recall = 0
        average_f1 = 0

        # progress_bar = tqdm(desc=eval_file.name)
        with open(eval_file.as_posix(), "r", encoding="utf-8") as f:
            for row in f:
                row = json.loads(row)
                duration = row["duration"]
                accuracy = row["accuracy"]
                precision = row["precision"]
                recall = row["recall"]
                f1 = row["f1"]

                total += 1
                total_duration += duration
                total_accuracy += accuracy * duration
                total_precision += precision * duration
                total_recall += recall * duration
                total_f1 += f1 * duration

                average_accuracy = total_accuracy / total_duration
                average_precision = total_precision / total_duration
                average_recall = total_recall / total_duration
                average_f1 = total_f1 / total_duration

                # progress_bar.update(1)
                # progress_bar.set_postfix({
                #     "total": total,
                #     "accuracy": average_accuracy,
                #     "precision": average_precision,
                #     "recall": average_recall,
                #     "f1": average_f1,
                #     "total_duration": f"{round(total_duration / 60, 4)}min",
                # })
        summary = (f"{eval_file.name}, "
                   f"total: {total}, "
                   f"accuracy: {average_accuracy}, "
                   f"precision: {average_precision}, "
                   f"recall: {average_recall}, "
                   f"f1: {average_f1}, "
                   f"total_duration: {f"{round(total_duration / 60, 4)}min"}, "
                   )
        print(summary)
    return


if __name__ == "__main__":
    main()