Upload predict.py
Browse files- predict.py +24 -0
predict.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
Created on Mon Jun 30 17:02:31 2025
|
| 4 |
+
|
| 5 |
+
@author: User
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
# predict.py
|
| 9 |
+
import joblib
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
# Cargar modelo y scaler
|
| 13 |
+
scaler = joblib.load("scaler.joblib")
|
| 14 |
+
model = joblib.load("svm_mfcc_model.joblib")
|
| 15 |
+
|
| 16 |
+
def predict_species(mfcc_features: np.ndarray) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Predicts the species given MFCC features (shape: [n_mfcc, n_frames]).
|
| 19 |
+
"""
|
| 20 |
+
# Flatten or average across time if needed
|
| 21 |
+
features = mfcc_features.mean(axis=1) # shape (n_mfcc,)
|
| 22 |
+
features = scaler.transform([features])
|
| 23 |
+
prediction = model.predict(features)
|
| 24 |
+
return prediction[0]
|