Skip to content

Commit b948dac

Browse files
docs: overhaul README for PyTorch migration and open-source readiness
1 parent cc1fc9b commit b948dac

1 file changed

Lines changed: 143 additions & 92 deletions

File tree

ReadMe.md

Lines changed: 143 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,83 @@
99
<p align="center">
1010
<a href="https://github.com/filippogiruzzi/voice_activity_detection"><img src="https://img.shields.io/github/stars/filippogiruzzi/voice_activity_detection?logo=github" alt="GitHub stars"></a>
1111
<a href="https://github.com/filippogiruzzi/voice_activity_detection"><img src="https://img.shields.io/github/forks/filippogiruzzi/voice_activity_detection?logo=github" alt="GitHub forks"></a>
12-
<a href="https://hub.docker.com/repository/docker/filippogrz/tf-vad"><img src="https://img.shields.io/docker/pulls/filippogrz/tf-vad?logo=docker" alt="Docker Pulls"></a>
12+
<a href="https://hub.docker.com/repository/docker/filippogrz/vad"><img src="https://img.shields.io/docker/pulls/filippogrz/vad?logo=docker" alt="Docker Pulls"></a>
1313
</p>
1414

15-
<center>Keywords: Python, TensorFlow, Deep Learning, Time Series classification</center>
16-
15+
<center>Keywords: Python, PyTorch, Deep Learning, Audio, Time Series classification, uv, Docker</center>
1716

1817
## Table of contents
1918

20-
1. [ Installation ](#1-installation)
21-
1.1 [ Basic installation ](#11-basic-installation)
22-
1.2 [ Virtual environment installation ](#12-virtual-environment-installation)
23-
1.3 [ Docker installation ](#13-docker-installation)
24-
2. [ Introduction ](#2-introduction)
25-
2.1 [ Goal ](#21-goal)
26-
2.2 [ Results ](#22-results)
19+
1. [ Installation ](#1-installation)
20+
2. [ Introduction ](#2-introduction)
2721
3. [ Project structure ](#3-project-structure)
2822
4. [ Dataset ](#4-dataset)
29-
5. [ Project usage ](#5-project-usage)
30-
5.1 [ Dataset automatic labeling ](#51-dataset-automatic-labeling)
31-
5.2 [ Record raw data to .tfrecord format ](#52-record-raw-data-to-tfrecord-format)
32-
5.3 [ Train a CNN to classify Speech & Noise signals ](#53-train-a-cnn-to-classify-speech--noise-signals)
33-
5.4 [ Export trained model & run inference on Test set ](#54-export-trained-model--run-inference-on-test-set)
34-
6. [ Todo ](#6-todo)
35-
7. [ Resources ](#7-resources)
23+
5. [ Project usage ](#5-project-usage)
24+
6. [ Testing ](#6-testing)
25+
7. [ Continuous integration & delivery ](#7-continuous-integration--delivery)
26+
8. [ Contributing ](#8-contributing)
27+
9. [ Todo ](#9-todo)
28+
10. [ License ](#10-license)
29+
11. [ Resources ](#11-resources)
3630

3731
## 1. Installation
3832

39-
This project was designed for:
40-
* Ubuntu 20.04
41-
* Python 3.7.3
42-
* TensorFlow 1.15.4
33+
This project uses:
34+
* Python 3.11+
35+
* PyTorch 2.2+
36+
* [uv](https://docs.astral.sh/uv/) package manager
4337

4438
```bash
45-
$ cd /path/to/project/
46-
$ git clone https://github.com/filippogiruzzi/voice_activity_detection.git
47-
$ cd voice_activity_detection/
39+
git clone https://github.com/filippogiruzzi/voice_activity_detection.git
40+
cd voice_activity_detection/
4841
```
4942

50-
### 1.1 Basic installation
51-
52-
:warning: It is recommended to use virtual environments !
43+
### 1.1 Install with uv (recommended)
5344

5445
```bash
55-
$ pyenv install 3.7.3
56-
$ pyenv virtualenv 3.7.3 vad-venv
57-
$ pyenv activate vad-venv
46+
# Install uv if you don't have it
47+
curl -LsSf https://astral.sh/uv/install.sh | sh
48+
49+
# Install all dependencies
50+
uv sync
5851
```
5952

53+
### 1.2 Development setup
54+
6055
```bash
61-
$ pip install -r requirements.txt
62-
$ pip install -e .
63-
```
56+
# Install with dev dependencies (ruff, pytest, etc.)
57+
uv sync
6458

65-
## 1.2 Virtual environment installation
59+
# Run linters
60+
make lint
6661

67-
## 1.3 Docker installation
62+
# Run tests
63+
make test
6864

69-
You can pull the latest image from DockerHub and run Python commands inside the container:
70-
```bash
71-
$ docker pull filippogrz/tf-vad:latest
72-
$ docker run --rm --gpus all -v /var/run/docker.sock:/var/run/docker.sock -it --entrypoint /bin/bash -e TF_FORCE_GPU_ALLOW_GROWTH=true filippogrz/tf-vad
65+
# Auto-format code
66+
make format
7367
```
7468

75-
If you want to build the docker image and run the container from scratch, run the following commands.
69+
### 1.3 Docker installation
7670

77-
Build the docker image:
71+
Build and run the CPU Docker image:
7872
```bash
79-
$ make build
73+
make build
74+
make local-nobuild
8075
```
81-
(This might take a while.)
8276

83-
Run the docker image:
77+
For GPU support (requires NVIDIA Docker runtime):
8478
```bash
85-
$ make local-nobuild
79+
make build-gpu
8680
```
8781

8882
## 2. Introduction
8983

9084
### 2.1 Goal
9185

92-
The purpose of this project is to design and implement
93-
a real-time Voice Activity Detection algorithm based on Deep Learning.
86+
The purpose of this project is to design and implement a real-time Voice Activity Detection algorithm based on Deep Learning.
9487

95-
The designed solution is based on MFCC feature extraction and
96-
a 1D-Resnet model that classifies whether a audio signal is
97-
speech or noise.
88+
The designed solution is based on a simple pipeline with MFCC feature extraction and a small 1D-ResNet model (PyTorch) that classifies whether an audio signal is speech or noise.
9889

9990
### 2.2 Results
10091

@@ -107,89 +98,149 @@ Raw and post-processed inference results on a test audio signal are shown below.
10798
![alt text](pics/inference_raw.png "Raw VAD inference")
10899
![alt text](pics/inference_smooth.png "VAD inference with post-processing")
109100

101+
### 2.3 Model & features
102+
103+
Each audio window of `SEQ_LEN = 1024` samples (16 kHz) is converted into a
104+
**16 × 65** feature tensor stacking:
105+
106+
* 5 MFCC coefficients,
107+
* 5 MFCC deltas (1st order),
108+
* 5 MFCC delta-deltas (2nd order),
109+
* 1 RMS energy.
110+
111+
These features feed a configurable 1D-ResNet (`vad.model.Resnet1D`):
112+
stacked residual blocks (3 × `Conv1d → BatchNorm1d` with a 1×1 shortcut) →
113+
global average pooling → a fully connected head producing a single speech logit.
114+
The architecture is fully described by the `ModelConfig` dataclass, so the same
115+
configuration must be used at training, export, and inference time.
116+
110117
## 3. Project structure
111118

112-
The project `voice_activity_detection/` has the following structure:
113-
* `vad/data_processing/`: raw data labeling, processing,
114-
recording & visualization
115-
* `vad/training/`: data, input pipeline, model
116-
& training / evaluation / prediction
117-
* `vad/inference/`: exporting trained model & inference
119+
The core code lives flat inside `vad/`:
120+
* `vad/model.py`: the `Resnet1D` model architecture and its `ModelConfig` dataclass
121+
* `vad/data.py`: feature extraction, dataset building & the PyTorch DataLoader
122+
* `vad/train.py`: training loop & model export (state dict + TorchScript)
123+
* `vad/inference.py`: sliding-window inference & visualization
124+
125+
Supporting files:
126+
* `tests/`: pytest integration tests (training → export → inference)
127+
* `scripts/`: Docker build / run helpers
128+
* `Makefile`: common developer commands (`install`, `lint`, `format`, `test`, `build`, ...)
129+
* `pyproject.toml`: project metadata, dependencies & tooling configuration
118130

119131
## 4. Dataset
120132

121-
Please download the LibriSpeech ASR corpus dataset from https://openslr.org/12/,
122-
and extract all files to : `/path/to/LibriSpeech/`.
133+
Please download the LibriSpeech ASR corpus dataset from https://openslr.org/12/,
134+
and extract all files to: `/path/to/LibriSpeech/`.
123135

124-
The dataset contains approximately 1000 hours of 16kHz read English speech
136+
The dataset contains approximately 1000 hours of 16kHz read English speech
125137
from audiobooks, and is well suited for Voice Activity Detection.
126138

127-
I automatically annotated the `test-clean` set of the dataset with a
139+
I automatically annotated the `test-clean` set of the dataset with a
128140
pretrained VAD model.
129141

130-
Please feel free to use the `labels/` folder and the pre-trained VAD model (only for inference) from this
142+
Please feel free to use the `labels/` folder and the pre-trained VAD model (only for inference) from this
131143
[ link ](https://drive.google.com/open?id=1ZPQ6wnMhHeE7XP5dqpAEmBAryFzESlin).
132144

145+
**Important note:** As this is only a toy project, it is designed to split the `test-clean` sub-dataset intro train / val / test for quick iteration, but can be extended to a full large-scale dataset.
146+
133147
## 5. Project usage
134148

149+
### 5.1 Create PyTorch dataset from raw audio
150+
135151
```bash
136-
$ cd /path/to/project/voice_activity_detection/vad/
152+
uv run vad-data --data-dir /path/to/LibriSpeech/
137153
```
138154

139-
### 5.1 Dataset automatic labeling
155+
This saves processed `.pt` files to `/path/to/LibriSpeech/dataset/{train,val,test}/`.
156+
Use `--max-files N` to process only a few files per split for a quick run.
140157

141-
Skip this subsection if you already have the `labels/` folder, that contains annotations
142-
from a different pre-trained model.
158+
### 5.2 Train & export the VAD model
143159

144160
```bash
145-
$ python data_processing/librispeech_label_data.py --data-dir /path/to/LibriSpeech/test-clean/ --exported-model /path/to/pretrained/model/
161+
uv run vad-train --data-dir /path/to/LibriSpeech/dataset/ --model-dir /path/to/models/
146162
```
147163

148-
This will record the annotations into `/path/to/LibriSpeech/labels/` as
149-
`.json` files.
164+
Checkpoints are saved to `--model-dir`, and the final model is exported (state dict +
165+
TorchScript) to `<model-dir>/exported/` unless `--no-export` is passed.
150166

151-
### 5.2 Record raw data to .tfrecord format
167+
Useful flags: `--epochs/-e`, `--batch-size/-b`, `--lr`, and the architecture flags
168+
`--n-filters` / `--fc-units`. Training device (CUDA, Apple MPS, or CPU) is selected
169+
automatically. TensorBoard logs are written to `<model-dir>/logs/`:
152170

153171
```bash
154-
$ python data_processing/data_to_tfrecords.py --data-dir /path/to/LibriSpeech/
172+
uv run tensorboard --logdir /path/to/models/logs/
155173
```
156174

157-
This will record the splitted data to `.tfrecord` format in `/path/to/LibriSpeech/tfrecords/`
158-
159-
### 5.3 Train a CNN to classify Speech & Noise signals
175+
### 5.3 Run inference
160176

161177
```bash
162-
$ python training/train.py --data-dir /path/to/LibriSpeech/tfrecords/
178+
uv run vad-inference \
179+
--data-dir /path/to/LibriSpeech/ \
180+
--checkpoint /path/to/models/exported/model_state_dict.pt \
181+
--smoothing --max-files 1
163182
```
164183

165-
### 5.4 Export trained model & run inference on Test set
184+
> **Note:** if you trained with custom `--n-filters` / `--fc-units`, pass the same
185+
> values to `vad-inference` so the checkpoint loads into a matching architecture.
186+
187+
## 6. Testing
188+
189+
Run the test suite with coverage:
166190

167191
```bash
168-
$ python inference/export_model.py --model-dir /path/to/trained/model/dir/
169-
$ python inference/inference.py --data-dir /path/to/LibriSpeech/ --exported-model /path/to/exported/model/ --smoothing
192+
make test
170193
```
171194

172-
The trained model will be recorded in `/path/to/LibriSpeech/tfrecords/models/resnet1d/`.
173-
The exported model will be recorded inside this directory.
195+
This runs `pytest` with coverage over the `vad` package, printing a
196+
term report with missing lines and writing an HTML report to `htmlcov/`.
197+
198+
## 7. Continuous integration & delivery
199+
200+
* **CI** ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)): on every push and
201+
pull request, runs `ruff` lint, `ruff format --check`, and the pytest suite.
202+
* **CD** ([`.github/workflows/cd.yml`](.github/workflows/cd.yml)): on push to
203+
`master`/`main`, builds the Docker image and pushes it to Docker Hub
204+
(tagged with the commit SHA and `latest`).
205+
206+
## 8. Contributing
207+
208+
Contributions are welcome! Please:
209+
210+
1. Fork the repository and create a feature branch.
211+
2. Install the dev environment with `uv sync`.
212+
3. Make sure `make lint` and `make test` pass before opening a pull request.
213+
4. Use clear commit messages and keep changes focused.
214+
215+
## 9. Todo
216+
217+
### 9.1 ML Engineering
218+
219+
- [ ] Add MLflow experiment tracking (params, metrics, artifacts)
220+
- [ ] Reach full unit-test coverage and add CI coverage reporting
221+
- [ ] Add online / streaming real-time inference
222+
- [ ] Serve the model via a REST/gRPC API (e.g. FastAPI + ONNX Runtime)
223+
- [ ] Add data/version control (DVC) and a model registry
224+
225+
### 9.2 Data Science
226+
227+
- [ ] Compare the model against a simple baseline and train on the full dataset
228+
- [ ] Add time-series data augmentation and improve class balancing
229+
- [ ] Study the ROC curve & tune the classification threshold
230+
- [ ] Explore self-supervised speech encoders (e.g. WavLM, wav2vec 2.0)
231+
- [ ] Benchmark modern lightweight VAD models (e.g. Silero VAD, Pyannote 3.x)
232+
174233

175-
## 6. Todo
234+
## 10. License
176235

177-
- [ ] Compare Deep Learning model to a simple baseline
178-
- [ ] Train on full dataset
179-
- [ ] Improve data balancing
180-
- [ ] Add time series data augmentation
181-
- [ ] Study ROC curve & classification threshold
182-
- [ ] Add online inference
183-
- [ ] Evaluate quantitatively post-processing methods on the Test set
184-
- [ ] Add model description & training graphs
185-
- [ ] Add Google Colab demo
236+
This project is licensed under the terms of the [GNU GPL v3](LICENSE).
186237

187-
## 7. Resources
238+
## 11. Resources
188239

189-
* _Voice Activity Detection for Voice User Interface_,
240+
* _Voice Activity Detection for Voice User Interface_,
190241
[Medium](https://medium.com/linagoralabs/voice-activity-detection-for-voice-user-interface-2d4bb5600ee3)
191242
* _Deep learning for time series classifcation: a review_,
192243
Fawaz et al., 2018, [Arxiv](https://arxiv.org/abs/1809.04356)
193-
* _Time Series Classification from Scratch
244+
* _Time Series Classification from Scratch
194245
with Deep Neural Networks: A Strong Baseline_, Wang et al., 2016,
195246
[Arxiv](https://arxiv.org/abs/1611.06455)

0 commit comments

Comments
 (0)