-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
46 lines (30 loc) · 1.07 KB
/
main.py
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
import os
import pickle
import joblib
import argparse
import numpy as np
from modules import extract
def scale(features, name):
scaler = joblib.load(f"weights/scalers/scaler_{name}.save")
return scaler.transform(features.reshape(1, -1))
def predict(filename):
mfcc, chroma, mel, zcr = extract.mean_feature(filename)
zcr = scale(zcr, "zcr").reshape(-1)
mfcc = scale(mfcc, "mfcc").reshape(-1)
chroma = scale(chroma, "chroma").reshape(-1)
mel = scale(mel, "mel").reshape(-1)
x = np.concatenate([zcr, mfcc, chroma, mel], axis=0).reshape(1, -1)
res = 0
model_list = os.listdir("weights/models/")
for name in model_list:
model = pickle.load(open("weights/models/" + name, "rb"))
res += model.predict(x)
return (res /len(model_list))[0]
parser = argparse.ArgumentParser(description="Covid-19 cough detection ")
parser.add_argument("-f", type=str, help="audio filename")
args = parser.parse_args()
if args.f:
res = predict(args.f)
print(res)
if 0.8 - res <= 1e-9:
print("Di cach ly di ban oi!!!")