CoolFace
Apppublic

Haseeb949/fluenta-backend

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
debug_model.py75 linesDownload Raw Back to root
1 2import joblib3import numpy as np4from pathlib import Path5import glob6 7MODEL_DIR = Path(r"C:/Users/X/Downloads/models/backend/models_retrained")8MODEL_FILE = "stutter_model_retrained.pkl"9SCALER_FILE = "scaler_retrained.pkl"10 11def test_model():12    model_path = MODEL_DIR / MODEL_FILE13    scaler_path = MODEL_DIR / SCALER_FILE14    15    if not model_path.exists():16        print(f"Model not found at {model_path}")17        return18        19    model = joblib.load(model_path)20    scaler = joblib.load(scaler_path)21    22    print(f"Loaded model type: {type(model)}")23    24    # helper25    def _print_pred(feats, label):26        X_scaled = scaler.transform([feats])27        pred = model.predict(X_scaled)28        proba = model.predict_proba(X_scaled) if hasattr(model, "predict_proba") else "N/A"29        print(f"{label}: Pred={pred}, Proba={proba}")30 31    print("\n--- Testing Fluent Samples ---")32    fluent_files = glob.glob("Dataset/custom/fluent/*.wav")[:3]33    for wav_f in fluent_files:34        try:35            from feature_extraction import extract_features36            feats = extract_features(wav_f)37            if feats is not None:38                _print_pred(feats, f"File: {wav_f}")39        except Exception as e:40            print(f"Error testing file {wav_f}: {e}")41 42    print("\n--- Testing Stutter Samples ---")43    stutter_files = glob.glob("Dataset/custom/stutter/*.wav")[:3]44    for wav_f in stutter_files:45        try:46            from feature_extraction import extract_features47            feats = extract_features(wav_f)48            if feats is not None:49                _print_pred(feats, f"File: {wav_f}")50        except Exception as e:51            print(f"Error testing file {wav_f}: {e}")52 53    print("\n--- Testing with Random Features ---")54    for i in range(2):55        random_features = np.random.randn(60)56        _print_pred(random_features, f"Random {i}")57 58    print("\n--- Testing with ZERO features ---")59    zero_features = np.zeros(60)60    _print_pred(zero_features, "Zeros")61 62    print("\n--- Testing with silent.wav ---")63    if Path("silent.wav").exists():64        try:65            from feature_extraction import extract_features66            feats = extract_features("silent.wav")67            if feats is not None:68                _print_pred(feats, "File: silent.wav")69        except Exception as e:70            print(f"Error testing silent.wav: {e}")71 72 73if __name__ == "__main__":74    test_model()75