flamo


Nameflamo JSON
Version 0.0.18 PyPI version JSON
download
home_pageNone
SummaryAn Open-Source Library for Frequency-Domain Differentiable Audio Processing
upload_time2024-12-17 08:36:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2024 Gloria Dal Santo, Gian Marco De Bortoli, Sebastian Jiro Schlecht Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords audio differentiable programming machine learning optimization signal processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flamo
[PyPI](https://pypi.org/project/flamo/) | [ICASSP25-arXiv](https://arxiv.org/abs/2409.08723) 

Open-source library for frequency-domain differentiable audio processing.

It contains differentiable implementation of common LTI audio systems modules with learnable parameters.

---

### ⚙️ Optimization of audio LTI systems

Available differentiable audio signal processors - in `flamo.processor.dsp`: 
- **Gains** : Gains, Matrices, Householder Matrices
- **Filters** : Biquads, State Variable Filters (SVF), Graphic Equalizers (GEQ), Parametric Equiliers (PEQ - not released yet)
- **Delays** : Integer Delays, Fractional Delays 

Transforms  - in `flamo.processor.dsp`: 
- **Transform** : FFT, iFFT, time anti-aliasing enabled FFT and iFFT 


Utilities, system designers, and optimization - in `flamo.processor.system`:
- **Series** : Serial chaining of differentiable systems 
- **Recursion** : Closed loop with assignable feedforward and feedback paths
- **Shell**: Container class for safe interaction between system, dataset, and loss functions

Optimization - in `flamo.optimize`:
- **Trianer** : Handling of the training and validation steps 
- **Dataset** : Customizable dataset class and helper methods 

--- 

### 🛠️ Installation
To install it via pip, on a new python virtual environment `flamo-env` 
```
python3.10 -m venv .flamo-env
source .flamo-env/bin/activate
pip install flamo
```
If you are using conda, you might need to install `libsndfile` manually
```
conda create -n flamo-env python=3.10
conda activate flamo-env
pip install flamo
conda install -c conda-forge libsndfile
```

For local installation: clone and install dependencies on a new pyton virtual environment `flamo-env` 
```
git clone https://github.com/gdalsanto/flamo
cd flamo
python3.10 -m venv .flamo-env
source .flamo-env/bin/activate
pip install -e .
```
Note that it requires python>=3.10

---

### 💻 How to use the library

We included a few examples in [`./examples`](https://github.com/gdalsanto/flamo/tree/main/examples) that take you through the library's API. 

The following example demonstrates how to optimize the parameters of Biquad filters to match a target magnitude response. This is just a toy example; you can create and optimize much more complex systems by cascading modules either serially or recursively. 

Import modules 
```ruby
import torch
import torch.nn as nn
from flamo.optimize.dataset import Dataset, load_dataset
from flamo.optimize.trainer import Trainer
from flamo.processor import dsp, system
from flamo.functional import signal_gallery, highpass_filter

```
Define parameters and target response with randomized cutoff frequency and gains

```ruby
in_ch, out_ch = 1, 2    # input and output channels
n_sections = 2  # number of cascaded biquad sections
fs = 48000      # sampling frequency
nfft = fs*2     # number of fft points

b, a = highpass_filter(
    fc=torch.tensor(fs/2)*torch.rand(size=(n_sections, out_ch, in_ch)), 
    gain=torch.tensor(-1) + (torch.tensor(2))*torch.rand(size=(n_sections, out_ch, in_ch)), 
    fs=fs)
B = torch.fft.rfft(b, nfft, dim=0)
A = torch.fft.rfft(a, nfft, dim=0)
target_filter = torch.prod(B, dim=1) / torch.prod(A, dim=1)

```

Define an instance of learnable Biquads

```ruby
filt = dsp.Biquad(
    size=(out_ch, in_ch), 
    n_sections=n_sections,
    filter_type='highpass',
    nfft=nfft,
    fs=fs,
    requires_grad=True,
    alias_decay_db=0,
)   
```

Use the `Shell` class to add input and output layers and to get the magnitude response at initialization 
Optimization is done in the frequency domain. The input will be an impulse in the time domain, thus the input layer should perform the Fourier transform.
The target is the magnitude response, so the output layer takes the absolute value of the filter's output.  

```ruby
input_layer = dsp.FFT(nfft)
output_layer = dsp.Transform(transform=lambda x : torch.abs(x))
model = system.Shell(core=filt, input_layer=input_layer, output_layer=output_layer)    
estimation_init = model.get_freq_response()

````

Set up optimization framework and launch it. The `Trainer` class is used to contain the model, training parameters, and training/valid steps in one class. 

```ruby
input = signal_gallery(1, n_samples=nfft, n=in_ch, signal_type='impulse', fs=fs)
target = torch.einsum('...ji,...i->...j', target_filter, input_layer(input))

dataset = Dataset(
    input=input,
    target=torch.abs(target),
    expand=100,
)
train_loader, valid_loader = load_dataset(dataset, batch_size=1)

trainer = Trainer(model, max_epochs=10, lr=1e-2, train_dir="./output")
trainer.register_criterion(nn.MSELoss(), 1)

trainer.train(train_loader, valid_loader)
```
end get the resulting response after optimization! 

```ruby
estimation = model.get_freq_response()
```

### 📖 Documentation 

A first version of the documentation is available on the repo's [Github Page](https://gdalsanto.github.io/flamo/). Note that we are currently working on improving the documentation to include examples, images, and a more pleasant template. 

---
### 📖 Reference

This work has been submitted to ICASSP 2025. Pre-print is available on [arxiv](https://arxiv.org/abs/2409.08723). 

```Dal Santo, G., De Bortoli, G. M., Prawda, K., Schlecht, S. J., & Välimäki, V. (2024). FLAMO: An Open-Source Library for Frequency-Domain Differentiable Audio Processing. arXiv preprint arXiv:2409.08723.```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flamo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Gloria Dal Santo <gloria.dalsanto@aalto.fi>, Gian Marco De Bortoli <gian.debortoli@aalto.fi>",
    "keywords": "audio, differentiable programming, machine learning, optimization, signal processing",
    "author": null,
    "author_email": "Gloria Dal Santo <gloria.dalsanto@aalto.fi>, Gian Marco De Bortoli <gian.debortoli@aalto.fi>, \"Sebastian J. Schlecht\" <sebastian.schlecht@fau.de>",
    "download_url": "https://files.pythonhosted.org/packages/be/aa/c97bf2e86e4675dfa01122aace788b6297d8a8b76a4cd919a205bec9795c/flamo-0.0.18.tar.gz",
    "platform": null,
    "description": "# flamo\n[PyPI](https://pypi.org/project/flamo/) | [ICASSP25-arXiv](https://arxiv.org/abs/2409.08723) \n\nOpen-source library for frequency-domain differentiable audio processing.\n\nIt contains differentiable implementation of common LTI audio systems modules with learnable parameters.\n\n---\n\n### \u2699\ufe0f Optimization of audio LTI systems\n\nAvailable differentiable audio signal processors - in `flamo.processor.dsp`: \n- **Gains** : Gains, Matrices, Householder Matrices\n- **Filters** : Biquads, State Variable Filters (SVF), Graphic Equalizers (GEQ), Parametric Equiliers (PEQ - not released yet)\n- **Delays** : Integer Delays, Fractional Delays \n\nTransforms  - in `flamo.processor.dsp`: \n- **Transform** : FFT, iFFT, time anti-aliasing enabled FFT and iFFT \n\n\nUtilities, system designers, and optimization - in `flamo.processor.system`:\n- **Series** : Serial chaining of differentiable systems \n- **Recursion** : Closed loop with assignable feedforward and feedback paths\n- **Shell**: Container class for safe interaction between system, dataset, and loss functions\n\nOptimization - in `flamo.optimize`:\n- **Trianer** : Handling of the training and validation steps \n- **Dataset** : Customizable dataset class and helper methods \n\n--- \n\n### \ud83d\udee0\ufe0f Installation\nTo install it via pip, on a new python virtual environment `flamo-env` \n```\npython3.10 -m venv .flamo-env\nsource .flamo-env/bin/activate\npip install flamo\n```\nIf you are using conda, you might need to install `libsndfile` manually\n```\nconda create -n flamo-env python=3.10\nconda activate flamo-env\npip install flamo\nconda install -c conda-forge libsndfile\n```\n\nFor local installation: clone and install dependencies on a new pyton virtual environment `flamo-env` \n```\ngit clone https://github.com/gdalsanto/flamo\ncd flamo\npython3.10 -m venv .flamo-env\nsource .flamo-env/bin/activate\npip install -e .\n```\nNote that it requires python>=3.10\n\n---\n\n### \ud83d\udcbb How to use the library\n\nWe included a few examples in [`./examples`](https://github.com/gdalsanto/flamo/tree/main/examples) that take you through the library's API. \n\nThe following example demonstrates how to optimize the parameters of Biquad filters to match a target magnitude response. This is just a toy example; you can create and optimize much more complex systems by cascading modules either serially or recursively. \n\nImport modules \n```ruby\nimport torch\nimport torch.nn as nn\nfrom flamo.optimize.dataset import Dataset, load_dataset\nfrom flamo.optimize.trainer import Trainer\nfrom flamo.processor import dsp, system\nfrom flamo.functional import signal_gallery, highpass_filter\n\n```\nDefine parameters and target response with randomized cutoff frequency and gains\n\n```ruby\nin_ch, out_ch = 1, 2    # input and output channels\nn_sections = 2  # number of cascaded biquad sections\nfs = 48000      # sampling frequency\nnfft = fs*2     # number of fft points\n\nb, a = highpass_filter(\n    fc=torch.tensor(fs/2)*torch.rand(size=(n_sections, out_ch, in_ch)), \n    gain=torch.tensor(-1) + (torch.tensor(2))*torch.rand(size=(n_sections, out_ch, in_ch)), \n    fs=fs)\nB = torch.fft.rfft(b, nfft, dim=0)\nA = torch.fft.rfft(a, nfft, dim=0)\ntarget_filter = torch.prod(B, dim=1) / torch.prod(A, dim=1)\n\n```\n\nDefine an instance of learnable Biquads\n\n```ruby\nfilt = dsp.Biquad(\n    size=(out_ch, in_ch), \n    n_sections=n_sections,\n    filter_type='highpass',\n    nfft=nfft,\n    fs=fs,\n    requires_grad=True,\n    alias_decay_db=0,\n)   \n```\n\nUse the `Shell` class to add input and output layers and to get the magnitude response at initialization \nOptimization is done in the frequency domain. The input will be an impulse in the time domain, thus the input layer should perform the Fourier transform.\nThe target is the magnitude response, so the output layer takes the absolute value of the filter's output.  \n\n```ruby\ninput_layer = dsp.FFT(nfft)\noutput_layer = dsp.Transform(transform=lambda x : torch.abs(x))\nmodel = system.Shell(core=filt, input_layer=input_layer, output_layer=output_layer)    \nestimation_init = model.get_freq_response()\n\n````\n\nSet up optimization framework and launch it. The `Trainer` class is used to contain the model, training parameters, and training/valid steps in one class. \n\n```ruby\ninput = signal_gallery(1, n_samples=nfft, n=in_ch, signal_type='impulse', fs=fs)\ntarget = torch.einsum('...ji,...i->...j', target_filter, input_layer(input))\n\ndataset = Dataset(\n    input=input,\n    target=torch.abs(target),\n    expand=100,\n)\ntrain_loader, valid_loader = load_dataset(dataset, batch_size=1)\n\ntrainer = Trainer(model, max_epochs=10, lr=1e-2, train_dir=\"./output\")\ntrainer.register_criterion(nn.MSELoss(), 1)\n\ntrainer.train(train_loader, valid_loader)\n```\nend get the resulting response after optimization! \n\n```ruby\nestimation = model.get_freq_response()\n```\n\n### \ud83d\udcd6 Documentation \n\nA first version of the documentation is available on the repo's [Github Page](https://gdalsanto.github.io/flamo/). Note that we are currently working on improving the documentation to include examples, images, and a more pleasant template. \n\n---\n### \ud83d\udcd6 Reference\n\nThis work has been submitted to ICASSP 2025. Pre-print is available on [arxiv](https://arxiv.org/abs/2409.08723). \n\n```Dal Santo, G., De Bortoli, G. M., Prawda, K., Schlecht, S. J., & V\u00e4lim\u00e4ki, V. (2024). FLAMO: An Open-Source Library for Frequency-Domain Differentiable Audio Processing. arXiv preprint arXiv:2409.08723.```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Gloria Dal Santo, Gian Marco De Bortoli, Sebastian Jiro Schlecht  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "An Open-Source Library for Frequency-Domain Differentiable Audio Processing",
    "version": "0.0.18",
    "project_urls": {
        "Homepage": "https://github.com/gdalsanto/flamo",
        "Issues": "https://github.com/gdalsanto/flamo/issues"
    },
    "split_keywords": [
        "audio",
        " differentiable programming",
        " machine learning",
        " optimization",
        " signal processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9bf20633f5eede196787f57a31d6f1c9da3fee51432cc2ae3143497bd9c4a9e0",
                "md5": "88ddd30ef16700cd0f21d9e0a293a88a",
                "sha256": "4efb4fc8221667313f0bd070a3b1f1465297dc76537ba1b2a0f1cb2e98c215a7"
            },
            "downloads": -1,
            "filename": "flamo-0.0.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "88ddd30ef16700cd0f21d9e0a293a88a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 51177,
            "upload_time": "2024-12-17T08:36:07",
            "upload_time_iso_8601": "2024-12-17T08:36:07.327610Z",
            "url": "https://files.pythonhosted.org/packages/9b/f2/0633f5eede196787f57a31d6f1c9da3fee51432cc2ae3143497bd9c4a9e0/flamo-0.0.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "beaac97bf2e86e4675dfa01122aace788b6297d8a8b76a4cd919a205bec9795c",
                "md5": "3b5f503f7382a3b0e857200c69b50eb0",
                "sha256": "3aa6582f5f3bb3b48001eea0411242afcb367c8931601f4a6d2180827294c621"
            },
            "downloads": -1,
            "filename": "flamo-0.0.18.tar.gz",
            "has_sig": false,
            "md5_digest": "3b5f503f7382a3b0e857200c69b50eb0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12733511,
            "upload_time": "2024-12-17T08:36:50",
            "upload_time_iso_8601": "2024-12-17T08:36:50.519912Z",
            "url": "https://files.pythonhosted.org/packages/be/aa/c97bf2e86e4675dfa01122aace788b6297d8a8b76a4cd919a205bec9795c/flamo-0.0.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 08:36:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gdalsanto",
    "github_project": "flamo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flamo"
}
        
Elapsed time: 0.41346s