DerrickLegacy256 commited on
Commit
c21f2aa
·
verified ·
1 Parent(s): 0a2b02c

Auto-deploy 2026-04-29 10:19 UTC

Browse files
README.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ tags:
4
+ - audio
5
+ - audio-classification
6
+ - bee
7
+ - hive-monitoring
8
+ - beekeeping
9
+ library_name: sklearn
10
+ license: mit
11
+ metrics:
12
+ - accuracy
13
+ - f1
14
+ ---
15
+
16
+ # Bee Audio Classifier
17
+
18
+ 5-class audio classifier for bee colony health monitoring.
19
+ Trained on segmented hive recordings using MFCC-based feature extraction.
20
+
21
+ > Last updated: 2026-04-29 10:19 UTC
22
+
23
+ ## Classes
24
+
25
+ | Label | Description |
26
+ |---|---|
27
+ | `active_colony` | — |
28
+ | `external_noise` | — |
29
+ | `missing_queen` | — |
30
+ | `queenbee_present` | — |
31
+ | `swarming` | — |
32
+
33
+ ## Model performance
34
+
35
+ | File | Description | Accuracy | F1 (weighted) |
36
+ |---|---|---|---|
37
+ | `random_forest_model.pkl` | Random Forest | 0.9966 | 0.9966 |
38
+ | `svm_rbf_model.pkl` | SVM (RBF) | 0.9950 | 0.9950 |
39
+ | `xgboost_model.pkl` | XGBoost | 0.9977 | 0.9977 |
40
+ | `gradient_boosting_model.pkl` | Gradient Boosting **best** | 0.9983 | 0.9983 |
41
+ | `bee_cnn_classifier.h5` | CNN (Mel Spectrogram) | — | — |
42
+ | `best_cnn.h5` | CNN checkpoint | — | — |
43
+
44
+ `label_encoder.pkl` is required by all classical ML models.
45
+ `cnn_label_encoder.pkl` is required by the CNN models.
46
+
47
+ ## Feature extraction (171 features per 5-second segment)
48
+
49
+ - 40 MFCCs × (mean + std) = 80
50
+ - 40 delta-MFCCs × mean = 40
51
+ - 12 Chroma × (mean + std) = 24
52
+ - Mel spectrogram stats (mean, std, max, min) = 4
53
+ - Spectral centroid (mean + std) = 2
54
+ - Spectral bandwidth (mean + std) = 2
55
+ - Spectral rolloff (mean + std) = 2
56
+ - Spectral contrast × 7 × mean = 7
57
+ - Zero crossing rate (mean + std) = 2
58
+ - RMS energy (mean + std) = 2
59
+ - Tonnetz × 6 × mean = 6
60
+
61
+ ## Quick Python usage
62
+
63
+ ```python
64
+ import joblib
65
+ import librosa
66
+ import numpy as np
67
+
68
+ model = joblib.load("gradient_boosting_model.pkl")
69
+ le = joblib.load("label_encoder.pkl")
70
+
71
+ def extract_features(y, sr, n_mfcc=40,
72
+ hop_length=512, n_fft=2048):
73
+ feats = {}
74
+ mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=n_mfcc, n_fft=n_fft, hop_length=hop_length)
75
+ for i in range(n_mfcc):
76
+ feats[f"mfcc_{i}_mean"] = np.mean(mfcc[i])
77
+ feats[f"mfcc_{i}_std"] = np.std(mfcc[i])
78
+ delta = librosa.feature.delta(mfcc)
79
+ for i in range(n_mfcc):
80
+ feats[f"mfcc_delta_{i}_mean"] = np.mean(delta[i])
81
+ chroma = librosa.feature.chroma_stft(y=y, sr=sr, n_fft=n_fft, hop_length=hop_length)
82
+ for i in range(12):
83
+ feats[f"chroma_{i}_mean"] = np.mean(chroma[i])
84
+ feats[f"chroma_{i}_std"] = np.std(chroma[i])
85
+ mel = librosa.feature.melspectrogram(y=y, sr=sr, hop_length=hop_length)
86
+ mel_db = librosa.power_to_db(mel, ref=np.max)
87
+ feats["mel_mean"] = np.mean(mel_db); feats["mel_std"] = np.std(mel_db)
88
+ feats["mel_max"] = np.max(mel_db); feats["mel_min"] = np.min(mel_db)
89
+ sc = librosa.feature.spectral_centroid(y=y, sr=sr, hop_length=hop_length)
90
+ feats["spectral_centroid_mean"] = np.mean(sc); feats["spectral_centroid_std"] = np.std(sc)
91
+ sb = librosa.feature.spectral_bandwidth(y=y, sr=sr, hop_length=hop_length)
92
+ feats["spectral_bandwidth_mean"] = np.mean(sb); feats["spectral_bandwidth_std"] = np.std(sb)
93
+ sr_f = librosa.feature.spectral_rolloff(y=y, sr=sr, hop_length=hop_length)
94
+ feats["spectral_rolloff_mean"] = np.mean(sr_f); feats["spectral_rolloff_std"] = np.std(sr_f)
95
+ contrast = librosa.feature.spectral_contrast(y=y, sr=sr, hop_length=hop_length)
96
+ for i in range(contrast.shape[0]):
97
+ feats[f"spectral_contrast_{i}_mean"] = np.mean(contrast[i])
98
+ zcr = librosa.feature.zero_crossing_rate(y, hop_length=hop_length)
99
+ feats["zcr_mean"] = np.mean(zcr); feats["zcr_std"] = np.std(zcr)
100
+ rms = librosa.feature.rms(y=y, hop_length=hop_length)
101
+ feats["rms_mean"] = np.mean(rms); feats["rms_std"] = np.std(rms)
102
+ harmonic = librosa.effects.harmonic(y)
103
+ tonnetz = librosa.feature.tonnetz(y=harmonic, sr=sr)
104
+ for i in range(6):
105
+ feats[f"tonnetz_{i}_mean"] = np.mean(tonnetz[i])
106
+ return np.array(list(feats.values())).reshape(1, -1)
107
+
108
+ y, sr = librosa.load("hive_recording.wav", sr=22050)
109
+ seg = y[:int(5.0 * sr)]
110
+ feat = extract_features(seg, sr)
111
+ pred = le.classes_[model.predict(feat)[0]]
112
+ print(pred)
113
+ ```
bee_cnn_classifier.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dcb1be340ce84d89cb03abaa265cddce29ee78ec90a055b4e759c7936be00764
3
+ size 10318104
best_cnn.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6e4b45fa411d0d0acc7fb26e475bc09057b645ddac9170c69d54869d58bb00a
3
+ size 10318104
cnn_label_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:132fdcaf80fc602d40a183d206b94e63d22dd0c22b8bea91bea1163c589bfe1c
3
+ size 647
config.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "sample_rate": 22050,
3
+ "segment_length_sec": 5.0,
4
+ "n_mfcc": 40,
5
+ "hop_length": 512,
6
+ "n_fft": 2048,
7
+ "model_type": "bee_audio_classifier",
8
+ "classes": [
9
+ "active_colony",
10
+ "external_noise",
11
+ "missing_queen",
12
+ "queenbee_present",
13
+ "swarming"
14
+ ],
15
+ "num_classes": 5,
16
+ "n_features": 171,
17
+ "best_model": "gradient_boosting_model.pkl",
18
+ "uploaded_files": [
19
+ "random_forest_model.pkl",
20
+ "svm_rbf_model.pkl",
21
+ "xgboost_model.pkl",
22
+ "gradient_boosting_model.pkl",
23
+ "bee_cnn_classifier.h5",
24
+ "best_cnn.h5",
25
+ "label_encoder.pkl",
26
+ "cnn_label_encoder.pkl"
27
+ ],
28
+ "classical_metrics": {
29
+ "Random Forest": {
30
+ "accuracy": 0.9966,
31
+ "f1_weighted": 0.9966,
32
+ "f1_macro": 0.9957
33
+ },
34
+ "XGBoost": {
35
+ "accuracy": 0.9977,
36
+ "f1_weighted": 0.9977,
37
+ "f1_macro": 0.9973
38
+ },
39
+ "SVM (RBF)": {
40
+ "accuracy": 0.995,
41
+ "f1_weighted": 0.995,
42
+ "f1_macro": 0.9938
43
+ },
44
+ "Gradient Boosting": {
45
+ "accuracy": 0.9983,
46
+ "f1_weighted": 0.9983,
47
+ "f1_macro": 0.9979
48
+ }
49
+ },
50
+ "cnn_metrics": {}
51
+ }
gradient_boosting_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce793d54b48e580ffdc24b8250160a4ca2260aac14f37732a2a34436d9ea2c4a
3
+ size 4146914
label_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a761a43dac73252b50c2af95a2cddd859a07a020e4dbd0811e9d95cc64dfe35d
3
+ size 552
random_forest_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77976f022f449436610037367ccdda46b8963eed470cd012042548e2df6f018b
3
+ size 4668026
svm_rbf_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ecbd9f7442a3257814566f9eec4f70cd12077746b0590770c1d231381edf75e
3
+ size 634641
xgboost_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:784667947415aa63e727e4515df120402e58b68917efb26eb9c8a3d485f627cc
3
+ size 1441526