[+] Accuracy calculation
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with open('C:\Workspace\EECS 6414\Datasets\CN-Celeb_flac\id_labels.json', 'r', encoding='UTF-8') as f:
|
||||||
|
labels = json.load(f)
|
||||||
|
|
||||||
|
with open('C:\Workspace\EECS 6414\Datasets\CN-Celeb_flac\ina_pf_map.json', 'r', encoding='UTF-8') as f:
|
||||||
|
pf = json.load(f)
|
||||||
|
|
||||||
|
correct_f = []
|
||||||
|
correct_m = []
|
||||||
|
incorrect_f = []
|
||||||
|
incorrect_m = []
|
||||||
|
|
||||||
|
for k in labels:
|
||||||
|
if k not in pf:
|
||||||
|
print(f'Skipped {k}')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if labels[k] == 'f':
|
||||||
|
if pf[k] > 0.5:
|
||||||
|
correct_f += k
|
||||||
|
else:
|
||||||
|
incorrect_f += k
|
||||||
|
|
||||||
|
if labels[k] == 'm':
|
||||||
|
if pf[k] < 0.5:
|
||||||
|
correct_m += k
|
||||||
|
else:
|
||||||
|
incorrect_m += k
|
||||||
|
|
||||||
|
print('Done Reading\n')
|
||||||
|
|
||||||
|
tp = len(correct_f)
|
||||||
|
tn = len(correct_m)
|
||||||
|
fp = len(incorrect_f)
|
||||||
|
fn = len(incorrect_m)
|
||||||
|
|
||||||
|
print('True Positive (F classified as F):', tp)
|
||||||
|
print('True Negative (M classified as M):', tn)
|
||||||
|
print('False Positive (F classified as M):', fp)
|
||||||
|
print('False Negative (M classified as F):', fn)
|
||||||
|
|
||||||
|
acc = (tp + tn) / (tp + tn + fp + fn)
|
||||||
|
precision_f = tp / (tp + fp)
|
||||||
|
recall_f = tp / (tp + fn)
|
||||||
|
precision_m = tn / (tn + fn)
|
||||||
|
recall_m = tn / (tn + fp)
|
||||||
|
|
||||||
|
print('Accuracy:', acc)
|
||||||
|
print('Precision F:', precision_f)
|
||||||
|
print('Recall F:', recall_f)
|
||||||
|
print('Precision M:', precision_m)
|
||||||
|
print('Recall M:', recall_m)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+17
-5
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import warnings
|
import warnings
|
||||||
@@ -178,15 +179,26 @@ def test():
|
|||||||
seg = Segmenter()
|
seg = Segmenter()
|
||||||
|
|
||||||
# Warmup run
|
# Warmup run
|
||||||
results = process(seg, ['../test.mp3'])
|
results = process(seg, ['../test.flac'])
|
||||||
print(results)
|
print(results)
|
||||||
|
|
||||||
# Actual run
|
# # Actual run
|
||||||
results = process(seg, ['../test.mp3'])
|
# results = process(seg, ['../test.flac'])
|
||||||
print(results)
|
# print(results)
|
||||||
|
|
||||||
|
# Benchmark
|
||||||
|
iterations = 60
|
||||||
|
total_time = 0
|
||||||
|
audio_file = '../test.flac'
|
||||||
|
audio_len = float(subprocess.getoutput(f'ffprobe -i {audio_file} -show_entries format=duration -v quiet -of csv="p=0"'))
|
||||||
|
|
||||||
|
for i in range(iterations):
|
||||||
|
results = process(seg, ['../test.flac'])
|
||||||
|
total_time += results.time_full
|
||||||
|
print(f'Benchmark result: {total_time}s / {iterations} iterations = {total_time / iterations / audio_len} seconds of processing per second in audio')
|
||||||
|
|
||||||
# Draw results
|
# Draw results
|
||||||
with draw_result('../test.mp3', results.results[0]) as buf:
|
with draw_result('../test.flac', results.results[0]) as buf:
|
||||||
show_image_buffer(buf)
|
show_image_buffer(buf)
|
||||||
print(get_result_percentages(results.results[0]))
|
print(get_result_percentages(results.results[0]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user