Skip to content

Commit

Permalink
dev (#5)
Browse files Browse the repository at this point in the history
* iWIP

* pre-commit

* wip

* fix pylint

* fix ruff

* fix mypy

* fix pyright

* fix docker base image (todo find latest working)

* WIP

* fix deprecation pkg_resources warnings

* wip

* wip

* wip

* wip

* wip

* disable python cache for tests

* fix typing

* wip

* add comment about python3.10 in README

* use image variable in Makefile

* evaluation wip

* [WIP] evaluation

* add tqdm progressbars

* write evaluation metrics to redis

* update evaluation

* wip

* ci

* _

* wip

* fix pre-commit
  • Loading branch information
tandav authored Mar 21, 2023
1 parent d00fa31 commit a20f0ef
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 96 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ on: push

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ['3.8', '3.9', '3.10', '3.11']
runs-on: [self-hosted, gpu]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

- name: install dependencies
run: python3 -m pip install .[dev]
- name: test gpu is available
run: nvidia-smi

- name: build image
run: make build

- name: test
run: pytest --cov pitch_detectors --cov-fail-under=90
run: make test

- name: test-no-gpu
run: make test-no-gpu

publish-to-pypi-and-github-release:
if: "startsWith(github.ref, 'refs/tags/')"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ipynb
64 changes: 64 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-yaml
- id: check-json
- id: check-ast
- id: check-byte-order-marker
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-merge-conflict
- id: detect-private-key
- id: double-quote-string-fixer
- id: name-tests-test
- id: requirements-txt-fixer

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.7.0
hooks:
- id: autopep8

- repo: https://github.com/PyCQA/autoflake
rev: v1.7.6
hooks:
- id: autoflake

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/PyCQA/pylint
rev: v2.17.0
hooks:
- id: pylint
additional_dependencies: ["pylint-per-file-ignores"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- id: mypy
additional_dependencies: [types-redis]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.299
hooks:
- id: pyright
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM alpine/curl as downloader
RUN curl -L https://tfhub.dev/google/spice/2?tf-hub-format=compressed --output spice_2.tar.gz && \
mkdir /spice_model && \
tar xvf spice_2.tar.gz --directory /spice_model && \
rm spice_2.tar.gz

FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04

# https://github.com/NVIDIA/nvidia-docker/wiki/Usage
# https://github.com/NVIDIA/nvidia-docker/issues/531
ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility

COPY --from=downloader /spice_model /spice_model

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get install -y python3.10-venv libsndfile-dev libasound-dev portaudio19-dev

# https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
ENV VIRTUAL_ENV=/venv
RUN python3.10 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

WORKDIR /app
COPY pyproject.toml .
COPY README.md .
COPY pitch_detectors /app/pitch_detectors
COPY tests /app/tests
COPY data /app/data

RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip setuptools wheel && \
pip install .[dev]
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
IMAGE = tandav/pitch-detectors:11.8.0-cudnn8-devel-ubuntu22.04

.PHONY: build
build:
DOCKER_BUILDKIT=1 docker build --progress=plain -t $(IMAGE) .

.PHONY: push
push:
docker push $(IMAGE)
docker push tandav/pitch-detectors:latest

.PHONY: test
test: build
docker run --rm -t --gpus all \
-e PITCH_DETECTORS_GPU=true \
$(IMAGE) \
pytest -v --cov pitch_detectors

.PHONY: test-no-gpu
test-no-gpu: build
docker run --rm -t \
-e PITCH_DETECTORS_GPU=false \
$(IMAGE) \
pytest -v --cov pitch_detectors

.PHONY: evaluation
evaluation: build
eval "$$(cat .env)"; \
docker run --rm -t --gpus all \
-e PITCH_DETECTORS_GPU=true \
-e REDIS_URL=$$REDIS_URL \
-v /home/tandav/Downloads/MIR-1K:/app/MIR-1K \
$(IMAGE) \
python pitch_detectors/evaluation.py
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@
collection of pitch detection algorithms with unified interface

## list of algorithms
1. PraatAC [cpu]
1. PraatCC [cpu]
1. PraatSHS [cpu]
1. Pyin [cpu]
1. Reaper [cpu]
1. Yaapt [cpu]
1. Rapt [cpu]
1. World [cpu]
1. TorchYin [cpu]
1. Crepe [cpu, gpu]
1. TorchCrepe [cpu, gpu]
1. Swipe [cpu, gpu]
<!-- table-start -->
| algorithm | cpu | gpu | accuracy [1] |
|------------------------------------------------------------------------------------------------------------|-----|-----|--------------|
| [PraatAC](https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.Sound.to_pitch_ac) || | 0.880 |
| [PraatCC](https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.Sound.to_pitch_cc) || | 0.893 |
| [PraatSHS](https://parselmouth.readthedocs.io/en/stable/api_reference.html#parselmouth.Sound.to_pitch_shs) || | 0.618 |
| [Pyin](https://librosa.org/doc/latest/generated/librosa.pyin.html) || | 0.886 |
| [Reaper](https://github.com/r9y9/pyreaper) || | 0.826 |
| [Yaapt](http://bjbschmitt.github.io/AMFM_decompy/pYAAPT.html#amfm_decompy.pYAAPT.yaapt) || | 0.759 |
| [World](https://github.com/JeremyCCHsu/Python-Wrapper-for-World-Vocoder) || | 0.873 |
| [TorchYin](https://github.com/brentspell/torch-yin) || | 0.886 |
| [Rapt](https://pysptk.readthedocs.io/en/stable/generated/pysptk.sptk.rapt.html) || | 0.859 |
| [Swipe](https://pysptk.readthedocs.io/en/stable/generated/pysptk.sptk.swipe.html) || | 0.871 |
| [Crepe](https://github.com/marl/crepe) ||| 0.802 |
| [TorchCrepe](https://github.com/maxrmorrison/torchcrepe) ||| 0.817 |
| [Spice](https://ai.googleblog.com/2019/11/spice-self-supervised-pitch-estimation.html) ||| 0.908 |
<!-- table-stop -->

## additional features
- robust (vote-based + median) averaging of pitch
- json import/export
- [1] accuracy is mean [raw pitch accuracy](http://craffel.github.io/mir_eval/#mir_eval.melody.raw_pitch_accuracy) on 1000 samples of [MIR-1K](https://www.kaggle.com/datasets/datongmuyuyi/mir1k) dataset

## install
all agorithms tested on python3.10, this is recommended python version to use
```bash
pip install pitch-detectors
```

## usage

```python
from scipy.io import wavfile
from pitch_detectors import algorithms
import matplotlib.pyplot as plt

fs, a = wavfile.read('data/b1a5da49d564a7341e7e1327aa3f229a.wav')
pitch = algorithms.Crepe(a, fs)
plt.plot(pitch.t, pitch.f0)
plt.show()
```

![Alt text](data/b1a5da49d564a7341e7e1327aa3f229a.png)


## additional features
- [ ] robust (vote-based + median) averaging of pitch
- [ ] json import/export
Binary file added data/b1a5da49d564a7341e7e1327aa3f229a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Loading

0 comments on commit a20f0ef

Please sign in to comment.