Views
No views yet
| Metric | Teacher | Student |
|---|---|---|
| AUROC | 0.9849 | 0.9195 |
| Compression | — | 17.02x smaller |
| AUROC Retention | — | 93.4% |
1import joblib, torch
2import numpy as np
3import librosa
4
5# Load the student bundle
6bundle = joblib.load('student_fusion_model.pkl')
7
8# --- Audio prediction ---
9# 1. Load and preprocess audio
10audio, _ = librosa.load('cough.wav', sr=22050, duration=5)
11audio = np.pad(audio, (0, max(0, 22050*5 - len(audio))))[:22050*5]
12mel = librosa.feature.melspectrogram(y=audio, sr=22050, n_mels=128, n_fft=2048, hop_length=512)
13log_mel = librosa.power_to_db(mel, ref=np.max)
14log_mel = (log_mel - log_mel.min()) / (log_mel.max() - log_mel.min() + 1e-8)
15mel_tensor = torch.FloatTensor(log_mel).unsqueeze(0).unsqueeze(0) # (1,1,128,T)
16
17# 2. Load student audio model (define StudentAudioCNN first — see repo)
18# audio_prob = torch.sigmoid(student_audio(mel_tensor)).item()
19
20# --- Clinical prediction ---
21import pandas as pd
22features = ['sex','age','height','weight','reported_cough_dur','hemoptysis',
23 'weight_loss','fever','night_sweats','smoke_lweek','heart_rate',
24 'temperature','tb_prior','tb_prior_Pul','tb_prior_Extrapul','tb_prior_Unknown']
25clinical_data = pd.DataFrame([[1,25,170,65,14,0,1,1,0,0,80,37.2,0,0,0,0]], columns=features)
26clinical_scaled = bundle['clinical_scaler'].transform(clinical_data)
27clinical_prob = bundle['clinical_model'].predict_proba(clinical_scaled)[0][1]
28
29# --- Fusion ---
30# final_prob = 0.28 * audio_prob + 0.72 * clinical_prob
31# prediction = 'TB Positive' if final_prob > 0.5 else 'TB Negative'
32
33## Method
34Offline Knowledge Distillation (Hinton et al., 2015)
35- Temperature T = 4.0
36- Alpha α = 0.7
37- Loss = α × T² × KL(teacher_soft ∥ student_soft) + (1−α) × BCE(hard_label)
38
39## Student Architecture
40- Audio: LightTBCNN (2 ResBlocks, 64 filters)
41- Clinical: MLP (32→16)
42- Fusion: Late fusion (28% audio + 72% clinical)
43
44⚠️ Research screening tool only — not a clinical diagnostic device.