Spaces:
Sleeping
Sleeping
Update readme.md
Browse files
readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
This project implements a **two-stage hierarchical deep learning system** that classifies washing-machine sounds as **Normal** or **Abnormal**, and further identifies the **sub-class** (e.g., wash mode, spin mode, dehydration noise, bearing noise, etc.) using **Mel-spectrograms** and **CNN models**.
|
| 4 |
|
|
@@ -12,79 +12,71 @@ The project contains:
|
|
| 12 |
|
| 13 |
---
|
| 14 |
|
| 15 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
βββ app.py # Gradio web app for prediction
|
| 18 |
-
|
| 19 |
-
βββ dl.py # Training script (CNN models for Stage 1 + subclasses)
|
| 20 |
-
|
| 21 |
-
βββ extractaudio.py # Script for testing audio files
|
| 22 |
-
|
| 23 |
-
βββ main_audio.py # Dependencies list (duplicated from requirements)
|
| 24 |
-
|
| 25 |
-
βββ requirements.txt # Project dependencies
|
| 26 |
-
|
| 27 |
-
βββ dl.py # Data pipeline for spectrograms
|
| 28 |
-
|
| 29 |
-
βββ MelSpectrograms/ # Generated spectrogram dataset
|
| 30 |
-
|
| 31 |
-
β βββ 00 - Abnormal/
|
| 32 |
-
|
| 33 |
-
β β βββ Bearing noise/
|
| 34 |
-
|
| 35 |
-
β β βββ Dehydration mode noise/
|
| 36 |
-
|
| 37 |
-
β βββ 01 - Normal/
|
| 38 |
-
|
| 39 |
-
β βββ Wash mode/
|
| 40 |
-
|
| 41 |
-
β βββ Spin mode/
|
| 42 |
-
|
| 43 |
-
βββ saved_models/ # Saved trained models (.h5) + label_meta.json
|
| 44 |
|
| 45 |
---
|
| 46 |
|
| 47 |
-
##
|
| 48 |
|
| 49 |
1) Clone the repository and move into it:
|
| 50 |
```bash
|
| 51 |
git clone <repo-url>
|
| 52 |
cd washing-machine-classifier
|
|
|
|
| 53 |
Create a virtual environment (recommended):
|
| 54 |
-
|
| 55 |
python -m venv .venv
|
| 56 |
source .venv/bin/activate # Linux/Mac
|
| 57 |
.venv\Scripts\activate # Windows
|
|
|
|
| 58 |
|
| 59 |
Install dependencies:
|
|
|
|
| 60 |
pip install -r requirements.txt
|
|
|
|
| 61 |
|
| 62 |
Data Preparation
|
| 63 |
Place your raw audio dataset in the following structure:
|
| 64 |
|
| 65 |
-
Washing machine/
|
| 66 |
-
|
| 67 |
-
βββ 00 -
|
| 68 |
-
|
| 69 |
-
β
|
| 70 |
-
|
| 71 |
-
β
|
| 72 |
-
|
| 73 |
-
βββ 01 -
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
βββ Spin mode/
|
| 78 |
-
|
| 79 |
-
Convert .wav files to Mel-Spectrograms:
|
| 80 |
-
|
| 81 |
python dl.py
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
Training Models
|
| 85 |
Run:
|
| 86 |
-
|
| 87 |
python dl.py
|
|
|
|
| 88 |
Trains Stage 1 model (Normal vs Abnormal).
|
| 89 |
|
| 90 |
Trains Stage 2 models (sub-classes for Normal and Abnormal).
|
|
@@ -112,39 +104,42 @@ View prediction result and generated spectrogram in the browser.
|
|
| 112 |
|
| 113 |
Example output:
|
| 114 |
|
| 115 |
-
π― Final Prediction:
|
| 116 |
-
|
| 117 |
-
Confidence Scores:
|
| 118 |
-
--------------------
|
| 119 |
-
Stage 1 (Normal): 0.9876
|
| 120 |
-
Stage 2 (Spin mode): 0.9451
|
| 121 |
-
Model Details
|
| 122 |
-
Input: Mel-spectrogram images (224x224x3)
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
Loss: Sparse categorical cross-entropy
|
| 131 |
-
|
| 132 |
-
Optimizer: Adam
|
| 133 |
|
| 134 |
-
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
-
See requirements.txt:
|
| 147 |
|
|
|
|
|
|
|
| 148 |
tensorflow
|
| 149 |
librosa
|
| 150 |
matplotlib
|
|
@@ -154,10 +149,6 @@ uvicorn[standard]
|
|
| 154 |
python-multipart
|
| 155 |
gradio
|
| 156 |
|
| 157 |
-
π¨βπ» Author
|
| 158 |
-
Developed by Anvit β Washing-machine sound anomaly detection with hierarchical deep learning.
|
| 159 |
-
|
| 160 |
-
---
|
| 161 |
|
| 162 |
|
| 163 |
|
|
|
|
| 1 |
+
# Washing-Machine Sound Classifier
|
| 2 |
|
| 3 |
This project implements a **two-stage hierarchical deep learning system** that classifies washing-machine sounds as **Normal** or **Abnormal**, and further identifies the **sub-class** (e.g., wash mode, spin mode, dehydration noise, bearing noise, etc.) using **Mel-spectrograms** and **CNN models**.
|
| 4 |
|
|
|
|
| 12 |
|
| 13 |
---
|
| 14 |
|
| 15 |
+
## Project Structure
|
| 16 |
+
|
| 17 |
+
βββ app.py # Gradio web app for prediction
|
| 18 |
+
βββ dl.py # Training script (CNN models for Stage 1 + subclasses)
|
| 19 |
+
βββ extractaudio.py # Script for testing audio files
|
| 20 |
+
βββ main_audio.py # Dependencies list (duplicated from requirements)
|
| 21 |
+
βββ requirements.txt # Project dependencies
|
| 22 |
+
βββ data_pipeline.py # Data pipeline for spectrograms
|
| 23 |
+
βββ MelSpectrograms/ # Generated spectrogram dataset
|
| 24 |
+
β βββ 00-Abnormal/
|
| 25 |
+
β β βββ 00-1 - Background noise/
|
| 26 |
+
β β βββ 00-2 - Dehydration mode noise/
|
| 27 |
+
β β βββ 00-3 - Wash mode noise/
|
| 28 |
+
β βββ 01-Normal/
|
| 29 |
+
β βββ 01-1 - Background noise/
|
| 30 |
+
β βββ 01-2 - Dehydration mode noise/
|
| 31 |
+
β βββ 01-3 - Wash mode noise/
|
| 32 |
+
βββ saved_models/ # Saved trained models (.h5) + label_meta.json
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
---
|
| 36 |
|
| 37 |
+
## Installation
|
| 38 |
|
| 39 |
1) Clone the repository and move into it:
|
| 40 |
```bash
|
| 41 |
git clone <repo-url>
|
| 42 |
cd washing-machine-classifier
|
| 43 |
+
```
|
| 44 |
Create a virtual environment (recommended):
|
| 45 |
+
```bash
|
| 46 |
python -m venv .venv
|
| 47 |
source .venv/bin/activate # Linux/Mac
|
| 48 |
.venv\Scripts\activate # Windows
|
| 49 |
+
```
|
| 50 |
|
| 51 |
Install dependencies:
|
| 52 |
+
```bash
|
| 53 |
pip install -r requirements.txt
|
| 54 |
+
```
|
| 55 |
|
| 56 |
Data Preparation
|
| 57 |
Place your raw audio dataset in the following structure:
|
| 58 |
|
| 59 |
+
βββ Washing machine/ # Generated spectrogram dataset
|
| 60 |
+
β βββ 00-Abnormal/
|
| 61 |
+
β β βββ 00-1 - Background noise/
|
| 62 |
+
β β βββ 00-2 - Dehydration mode noise/
|
| 63 |
+
β β βββ 00-3 - Wash mode noise/
|
| 64 |
+
β βββ 01-Normal/
|
| 65 |
+
β βββ 01-1 - Background noise/
|
| 66 |
+
β βββ 01-2 - Dehydration mode noise/
|
| 67 |
+
β βββ 01-3 - Wash mode noise/
|
| 68 |
+
|
| 69 |
+
Convert .wav files to Mel-Spectrograms
|
| 70 |
+
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
python dl.py
|
| 72 |
+
```
|
| 73 |
+
This will generate the MelSpectrograms/dataset.
|
| 74 |
|
| 75 |
Training Models
|
| 76 |
Run:
|
| 77 |
+
```bash
|
| 78 |
python dl.py
|
| 79 |
+
```
|
| 80 |
Trains Stage 1 model (Normal vs Abnormal).
|
| 81 |
|
| 82 |
Trains Stage 2 models (sub-classes for Normal and Abnormal).
|
|
|
|
| 104 |
|
| 105 |
Example output:
|
| 106 |
|
| 107 |
+
π― Final Prediction: 00-Abnormal β 00-1 - Background noise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
# Model Summary & Confidence Scores
|
| 110 |
|
| 111 |
+
## Confidence Scores
|
| 112 |
+
- **Stage 1 (Normal vs Abnormal):** 0.9876
|
| 113 |
+
- **Stage 2 (Sub-class within Normal, e.g., Spin mode):** 0.9451
|
| 114 |
|
| 115 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
## Model Details
|
| 118 |
|
| 119 |
+
- **Input:** Mel-spectrogram images (`224Γ224Γ3`)
|
| 120 |
+
- **Backbone:** Simple CNN
|
| 121 |
+
- `Conv2D + ReLU β MaxPooling`
|
| 122 |
+
- `Flatten β Dense β Dropout β Dense β Softmax`
|
| 123 |
+
- **Stage 1:** Normal vs Abnormal classification
|
| 124 |
+
- **Stage 2:** Sub-classification within Normal / Abnormal
|
| 125 |
|
| 126 |
+
### Training
|
| 127 |
+
- **Loss:** Sparse Categorical Cross-Entropy
|
| 128 |
+
- **Optimizer:** Adam
|
| 129 |
+
- **Metrics:** Accuracy
|
| 130 |
|
| 131 |
+
---
|
| 132 |
|
| 133 |
+
## Future Improvements
|
| 134 |
+
- Replace simple CNN with **MobileNetV2** or **EfficientNet** for higher accuracy.
|
| 135 |
+
- Add **data augmentation**: noise injection, pitch/time shift, random time masking.
|
| 136 |
+
- Deploy as a **FastAPI** service for production.
|
| 137 |
+
- Containerize with **Docker** for easy deployment.
|
| 138 |
|
| 139 |
+
---
|
|
|
|
| 140 |
|
| 141 |
+
## Requirements
|
| 142 |
+
```text
|
| 143 |
tensorflow
|
| 144 |
librosa
|
| 145 |
matplotlib
|
|
|
|
| 149 |
python-multipart
|
| 150 |
gradio
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
|