Update tasks/audio.py
Browse files- tasks/audio.py +5 -3
tasks/audio.py
CHANGED
@@ -10,7 +10,7 @@ import numpy as np
|
|
10 |
import scipy
|
11 |
|
12 |
from sklearn.preprocessing import StandardScaler
|
13 |
-
from .fourier import FourierPreprocessor
|
14 |
|
15 |
from .utils.evaluation import AudioEvaluationRequest
|
16 |
from .utils.emissions import tracker, clean_emissions_data, get_space_info
|
@@ -22,7 +22,8 @@ router = APIRouter()
|
|
22 |
|
23 |
DESCRIPTION = "Random Forest"
|
24 |
ROUTE = "/audio"
|
25 |
-
MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler.pkl"
|
|
|
26 |
# MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler_cloudpickle.pkl"
|
27 |
|
28 |
|
@@ -64,13 +65,14 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
64 |
|
65 |
# Extract audio samples from test_dataset
|
66 |
x_test = [sample["audio"]["array"] for sample in test_dataset]
|
|
|
67 |
|
68 |
clf = joblib.load(MODEL_PATH)
|
69 |
|
70 |
# with open(MODEL_PATH, 'rb') as f:
|
71 |
# clf = pickle.load(f)
|
72 |
|
73 |
-
predictions = clf.predict(
|
74 |
|
75 |
# --------------------------------------------------------------------------------------------
|
76 |
# YOUR MODEL INFERENCE STOPS HERE
|
|
|
10 |
import scipy
|
11 |
|
12 |
from sklearn.preprocessing import StandardScaler
|
13 |
+
from .fourier import FourierPreprocessor
|
14 |
|
15 |
from .utils.evaluation import AudioEvaluationRequest
|
16 |
from .utils.emissions import tracker, clean_emissions_data, get_space_info
|
|
|
22 |
|
23 |
DESCRIPTION = "Random Forest"
|
24 |
ROUTE = "/audio"
|
25 |
+
# MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler.pkl"
|
26 |
+
MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler_rawData.pkl"
|
27 |
# MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler_cloudpickle.pkl"
|
28 |
|
29 |
|
|
|
65 |
|
66 |
# Extract audio samples from test_dataset
|
67 |
x_test = [sample["audio"]["array"] for sample in test_dataset]
|
68 |
+
x_test_preprocessed = FourierPreprocessor().transform(x_test)
|
69 |
|
70 |
clf = joblib.load(MODEL_PATH)
|
71 |
|
72 |
# with open(MODEL_PATH, 'rb') as f:
|
73 |
# clf = pickle.load(f)
|
74 |
|
75 |
+
predictions = clf.predict(x_test_preprocessed)
|
76 |
|
77 |
# --------------------------------------------------------------------------------------------
|
78 |
# YOUR MODEL INFERENCE STOPS HERE
|