From 4fcecdd22f7701e6273b3bddf98bbdff97c1e0a5 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 16:09:55 +0530 Subject: [PATCH 01/22] add models dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6eb0fe3..fb3f3de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ #local +models/ cli/train_config/dataset/Vctk_local.yaml .DS_Store outputs/ From 2683940ff4287fa158fb73d249e69c9e2715d6da Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 16:11:50 +0530 Subject: [PATCH 02/22] control mlflow logging --- enhancer/models/model.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/enhancer/models/model.py b/enhancer/models/model.py index 6e6b4e1..cbbfad8 100644 --- a/enhancer/models/model.py +++ b/enhancer/models/model.py @@ -120,7 +120,11 @@ class Model(pl.LightningModule): loss = self.loss(prediction, target) - if self.logger: + if ( + (self.logger) + and (self.global_step > 50) + and (self.global_step % 50 == 0) + ): self.logger.experiment.log_metric( run_id=self.logger.run_id, key="train_loss", @@ -141,7 +145,11 @@ class Model(pl.LightningModule): self.log("val_metric", metric_val.item()) self.log("val_loss", loss_val.item()) - if self.logger: + if ( + (self.logger) + and (self.global_step > 50) + and (self.global_step % 50 == 0) + ): self.logger.experiment.log_metric( run_id=self.logger.run_id, key="val_loss", From 8be9fe614f28dfbaf9fe5e04545ddc712db15365 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 16:12:05 +0530 Subject: [PATCH 03/22] ignore ckpt files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fb3f3de..9cd222c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ #local -models/ +*.ckpt cli/train_config/dataset/Vctk_local.yaml .DS_Store outputs/ From 0d72b3d81807c79f18589aa0eebe68916dda71cb Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:24:39 +0530 Subject: [PATCH 04/22] setup files --- enhancer/version.py | 1 + setup.cfg | 100 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 63 ++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 enhancer/version.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/enhancer/version.py b/enhancer/version.py new file mode 100644 index 0000000..f102a9c --- /dev/null +++ b/enhancer/version.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8916eaa --- /dev/null +++ b/setup.cfg @@ -0,0 +1,100 @@ +# This file is used to configure your project. +# Read more about the various options under: +# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files + +[metadata] +name = enhancer +description = Deep learning for speech enhacement +author = Shahul Ess +author-email = shahules786@gmail.com +license = mit +long-description = file: README.md +long-description-content-type = text/markdown; charset=UTF-8; variant=GFM +# Change if running only on Windows, Mac or Linux (comma-separated) +platforms = Linux, Mac +# Add here all kinds of additional classifiers as defined under +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +classifiers = + Development Status :: 4 - Beta + Programming Language :: Python + +[options] +zip_safe = False +packages = find: +include_package_data = True +# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! +setup_requires = setuptools +# Add here dependencies of your project (semicolon/line-separated), e.g. +# install_requires = numpy; scipy +# Require a specific Python version, e.g. Python 2.7 or >= 3.4 +python_requires = >=3.8 + +[options.packages.find] +where = . +exclude = + tests + +[options.extras_require] +# Add here additional requirements for extra features, to install with: +# `pip install fastaudio[PDF]` like: +# PDF = ReportLab; RXP +# Add here test requirements (semicolon/line-separated) +testing = + pytest>=7.1.3 + pytest-cov>=4.0.0 +dev = + pre-commit>=2.20.0 + black>=22.8.0 + flake8>=5.0.4 +cli = + hydra-core >=1.1,<=1.2 + + +[options.entry_points] + +console_scripts = + enhancer-train=enhancer.cli.train:train + +[test] +# py.test options when running `python setup.py test` +# addopts = --verbose +extras = True + +[tool:pytest] +# Options for py.test: +# Specify command line options as you would do when invoking py.test directly. +# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml +# in order to write a coverage file that can be read by Jenkins. +addopts = + --cov pyannote --cov-report term-missing + --verbose +norecursedirs = + dist + build + .tox +testpaths = tests + +[aliases] +dists = bdist_wheel + +[bdist_wheel] +# Use this option if your package is pure-python +universal = 1 + +[build_sphinx] +source_dir = doc +build_dir = build/sphinx + +[devpi:upload] +# Options for the devpi: PyPI server and packaging tool +# VCS export must be deactivated since we are using setuptools-scm +no-vcs = 1 +formats = bdist_wheel + +[flake8] +# Some sane defaults for the code style checker flake8 +exclude = + .tox + build + dist + .eggs diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..79282b3 --- /dev/null +++ b/setup.py @@ -0,0 +1,63 @@ +import os +import sys +from pathlib import Path + +from pkg_resources import VersionConflict, require +from setuptools import find_packages, setup + +with open("README.md") as f: + long_description = f.read() + +with open("requirements.txt") as f: + requirements = f.read().splitlines() + +try: + require("setuptools>=38.3") +except VersionConflict: + print("Error: version of setuptools is too old (<38.3)!") + sys.exit(1) + + +ROOT_DIR = Path(__file__).parent.resolve() +# Creating the version file + +with open("version.txt") as f: + version = f.read() + +version = version.strip() +sha = "Unknown" + +if os.getenv("BUILD_VERSION"): + version = os.getenv("BUILD_VERSION") +elif sha != "Unknown": + version += "+" + sha[:7] +print("-- Building version " + version) + +version_path = ROOT_DIR / "enhancer" / "version.py" + +with open(version_path, "w") as f: + f.write("__version__ = '{}'\n".format(version)) + +if __name__ == "__main__": + setup( + name="enhancer", + namespace_packages=["enhancer"], + version=version, + packages=find_packages(), + install_requires=requirements, + description="Deep learning toolkit for speech enhancement", + long_description=long_description, + long_description_content_type="text/markdown", + author="Shahul Es", + author_email="shahules786@gmail.com", + url="", + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Scientific/Engineering", + ], + ) From 283a07f197767dc64f1f54cb5585eb6d21f1e2b2 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:24:55 +0530 Subject: [PATCH 05/22] version --- version.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 version.txt diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.1 From cb20c08095f024aa24d29fd5d148dad692fb89b4 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:25:32 +0530 Subject: [PATCH 06/22] namespace --- enhancer/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enhancer/__init__.py b/enhancer/__init__.py index f102a9c..5284146 100644 --- a/enhancer/__init__.py +++ b/enhancer/__init__.py @@ -1 +1 @@ -__version__ = "0.0.1" +__import__("pkg_resources").declare_namespace(__name__) From 078b9274fadab84d3c76f96639e9d606d499c2ea Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:26:00 +0530 Subject: [PATCH 07/22] install enhancer dev --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b3c716..d206744 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,6 +39,9 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt pip install black flake8 pytest-cov + - name: Install enhancer + run: | + pip install -e .[dev,testing] - name: Run black run: black --check . From 465f5a9262d1e6a1a8bfc2d15eff6167ce103e40 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:40:08 +0530 Subject: [PATCH 08/22] rmv flake8 --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d206744..745b749 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,9 +44,9 @@ jobs: pip install -e .[dev,testing] - name: Run black run: - black --check . + black --check . --exclude version.py - name: Run flake8 - run: flake8 + run: flake8 --max-line-length 120 --exclude __init__.py --ignore errors E203 - name: Test with pytest run: pytest tests --cov=enhancer/ From 72287dd42c079089e774f76acb2fe6c74cd7d29b Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:42:41 +0530 Subject: [PATCH 09/22] rmv flake8 --- .github/workflows/ci.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 745b749..1cf8570 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,15 +38,13 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install black flake8 pytest-cov + pip install black pytest-cov - name: Install enhancer run: | pip install -e .[dev,testing] - name: Run black run: - black --check . --exclude version.py - - name: Run flake8 - run: flake8 --max-line-length 120 --exclude __init__.py --ignore errors E203 + black --check . --exclude version.py¯ - name: Test with pytest run: pytest tests --cov=enhancer/ From f6d5e924f788c77975b463d8952e0a80db20ccb8 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:51:21 +0530 Subject: [PATCH 10/22] ignore version.py --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1cf8570..a4124c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,7 +44,7 @@ jobs: pip install -e .[dev,testing] - name: Run black run: - black --check . --exclude version.py¯ + black --check . --exclude enhancer/version.py¯ - name: Test with pytest run: pytest tests --cov=enhancer/ From 975e8bc50e5433d5c36c61083e71d0eb6fce709e Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 17:51:37 +0530 Subject: [PATCH 11/22] ignore version.py --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a4124c9..43b9e5e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,7 +44,7 @@ jobs: pip install -e .[dev,testing] - name: Run black run: - black --check . --exclude enhancer/version.py¯ + black --check . --exclude enhancer/version.py - name: Test with pytest run: pytest tests --cov=enhancer/ From 3084ffac198edeb64c19065f22c06192c088675d Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 20:51:18 +0530 Subject: [PATCH 12/22] fix version --- enhancer/models/model.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/enhancer/models/model.py b/enhancer/models/model.py index cbbfad8..e7c5879 100644 --- a/enhancer/models/model.py +++ b/enhancer/models/model.py @@ -11,10 +11,10 @@ from huggingface_hub import cached_download, hf_hub_url from pytorch_lightning.utilities.cloud_io import load as pl_load from torch.optim import Adam -from enhancer import __version__ from enhancer.data.dataset import EnhancerDataset from enhancer.inference import Inference from enhancer.loss import Avergeloss +from enhancer.version import __version__ CACHE_DIR = "" HF_TORCH_WEIGHTS = "" @@ -298,10 +298,9 @@ class Model(pl.LightningModule): ), f"Expected batch with 3 dimensions (batch,channels,samples) got only {batch.ndim}" batch_predictions = [] self.eval().to(self.device) - with torch.no_grad(): for batch_id in range(0, batch.shape[0], batch_size): - batch_data = batch[batch_id : batch_id + batch_size, :, :].to( + batch_data = batch[batch_id : (batch_id + batch_size), :, :].to( self.device ) prediction = self(batch_data) From ae3064549764ee0d17caa249ab8d8c73ec425b53 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 20:51:35 +0530 Subject: [PATCH 13/22] add sndfile --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 43b9e5e..c653451 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,6 +37,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install sndfile pip install -r requirements.txt pip install black pytest-cov - name: Install enhancer @@ -44,7 +45,7 @@ jobs: pip install -e .[dev,testing] - name: Run black run: - black --check . --exclude enhancer/version.py + black --check . --exclude enhancer/version.pyß - name: Test with pytest run: pytest tests --cov=enhancer/ From 48a95343efcb034fd1ed5bc49849a032e07bbec4 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 20:54:56 +0530 Subject: [PATCH 14/22] add sndfile --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c653451..469d88f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,7 +37,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install sndfile + pip install soundfile pip install -r requirements.txt pip install black pytest-cov - name: Install enhancer From a31af50c8f7ecce8d0af86d064b697df843fb7fa Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 20:58:49 +0530 Subject: [PATCH 15/22] fix typo --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 469d88f..fa07cc3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,7 +45,7 @@ jobs: pip install -e .[dev,testing] - name: Run black run: - black --check . --exclude enhancer/version.pyß + black --check . --exclude enhancer/version.py - name: Test with pytest run: pytest tests --cov=enhancer/ From cf0372b7d9b8ed95b338768b040f4d370b88f22e Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:07:40 +0530 Subject: [PATCH 16/22] add soundfile --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index bb13983..5f1c4f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ protobuf>=3.19.6 pytorch-lightning>=1.7.7 scikit-learn>=1.1.2 scipy>=1.9.1 +soundfile>=0.11.0 torch>=1.12.1 torchaudio>=0.12.1 tqdm>=4.64.1 From 2e0a6b636b080cc451fd2f113d3de370e0073819 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:08:02 +0530 Subject: [PATCH 17/22] fix docs --- enhancer/models/model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/enhancer/models/model.py b/enhancer/models/model.py index e7c5879..7ff15e4 100644 --- a/enhancer/models/model.py +++ b/enhancer/models/model.py @@ -217,8 +217,7 @@ class Model(pl.LightningModule): to True or to a string containing your hugginface.co authentication token that can be obtained by running `huggingface-cli login` cache_dir: Path or str, optional - Path to model cache directory. Defaults to content of PYANNOTE_CACHE - environment variable, or "~/.cache/torch/pyannote" when unset. + Path to model cache directory kwargs: optional Any extra keyword args needed to init the model. Can also be used to override saved hyperparameter values. From 69ece5b811f766c1cae23f7493d0d4bca7ae5efa Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:08:20 +0530 Subject: [PATCH 18/22] to numpy --- enhancer/inference.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/enhancer/inference.py b/enhancer/inference.py index fd3b518..d9282fd 100644 --- a/enhancer/inference.py +++ b/enhancer/inference.py @@ -139,7 +139,9 @@ class Inference: if filename.is_file(): raise FileExistsError(f"file {filename} already exists") else: - wavfile.write(filename, rate=sr, data=waveform.detach().cpu()) + wavfile.write( + filename, rate=sr, data=waveform.detach().cpu().numpy() + ) @staticmethod def prepare_output( From 428d3548a0a994d33e5e9a4bd948ea0ce780b72b Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:08:46 +0530 Subject: [PATCH 19/22] rmv typo --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 8916eaa..309ac9a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ extras = True # e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml # in order to write a coverage file that can be read by Jenkins. addopts = - --cov pyannote --cov-report term-missing + --cov enhancer --cov-report term-missing --verbose norecursedirs = dist From e15011d668f97cdd24eacb43a258768190c69c44 Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:09:11 +0530 Subject: [PATCH 20/22] mv install to requirements --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fa07cc3..43b9e5e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,7 +37,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install soundfile pip install -r requirements.txt pip install black pytest-cov - name: Install enhancer From 95c30d0835d572a4ed44161151970abb8868556b Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:15:35 +0530 Subject: [PATCH 21/22] sudo install --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 43b9e5e..4c64745 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,6 +37,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + sudo apt-get install libsndfile1 pip install -r requirements.txt pip install black pytest-cov - name: Install enhancer From bf81df8970f24fe54506d3bc36bbe061e97e48aa Mon Sep 17 00:00:00 2001 From: shahules786 Date: Thu, 6 Oct 2022 21:27:20 +0530 Subject: [PATCH 22/22] lazy fixture --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5f1c4f0..3762fd2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ librosa>=0.9.2 mlflow>=1.29.0 numpy>=1.23.3 protobuf>=3.19.6 +pytest-lazy-fixture>=0.6.3 pytorch-lightning>=1.7.7 scikit-learn>=1.1.2 scipy>=1.9.1