MIT License

项目介绍

yoyolicoris/pytorch-NMF 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 253 个 Star、23 次 Fork。

仓库全名
yoyolicoris/pytorch-NMF
开源许可证
MIT License
Star 数
253
Fork 数
23
未关闭 Issue
8

README 摘要

Non-negative Matrix Fatorization in PyTorch PyTorch is not only a good deep learning framework, but also a fast tool when it comes to matrix operations and convolutions on large data. A great example is PyTorchWavelets. In this package I implement NMF, PLCA and their deconvolutional variations in PyTorch based on torch.nn.Module, so the models can be moved freely among CPU/GPU devices and utilize parallel…

完整内容见 GitHub 原始 README 或本页 。

常见问题

pytorch-NMF 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 253 个 Star。

pytorch-NMF 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 pytorch-NMF 的源码?

可以直接克隆仓库:git clone https://github.com/yoyolicoris/pytorch-NMF.git,默认分支为 master;安装与运行步骤见仓库 README。

pytorch-NMF 最近还在维护吗?

仓库最近一次更新为 2024年7月25日,当前有 8 个未关闭 Issue;Star 数为 253,可作为社区活跃度的参考。

关于

A pytorch package for non-negative matrix factorization.

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
305
价值分
158
活跃状态
活跃

README

Non-negative Matrix Fatorization in PyTorch

build Upload Python Package codecov Documentation Status PyPI version

PyTorch is not only a good deep learning framework, but also a fast tool when it comes to matrix operations and convolutions on large data. A great example is PyTorchWavelets.

In this package I implement NMF, PLCA and their deconvolutional variations in PyTorch based on torch.nn.Module, so the models can be moved freely among CPU/GPU devices and utilize parallel computation of cuda. We also utilize the computational graph from torch.autograd to derive updated coefficients so the amount of codes is reduced and easy to maintain.

Modules

NMF

Basic NMF and NMFD module minimizing beta-divergence using multiplicative update rules.

The interface is similar to sklearn.decomposition.NMF with some extra options.

  • NMF: Original NMF algorithm.
  • NMFD: 1-D deconvolutional NMF algorithm.
  • NMF2D: 2-D deconvolutional NMF algorithm.
  • NMF3D: 3-D deconvolutional NMF algorithm.

PLCA

Basic PLCA and SIPLCA module using EM algorithm to minimize KL-divergence between the target distribution and the estimated distribution.

  • PLCA: Original PLCA (Probabilistic Latent Component Analysis) algorithm.
  • SIPLCA: Shift-Invariant PLCA algorithm (similar to NMFD).
  • SIPLCA2: 2-D deconvolutional SIPLCA algorithm.
  • SIPLCA3: 3-D deconvolutional SIPLCA algorithm.

Usage

Here is a short example of decompose a spectrogram using deconvolutional NMF:

import torch
import librosa
from torchnmf.nmf import NMFD
from torchnmf.metrics import kl_div

y, sr = librosa.load(librosa.util.example_audio_file())
y = torch.from_numpy(y)
windowsize = 2048
S = torch.stft(y, windowsize, 
               window=torch.hann_window(windowsize),
               return_complex=True).abs().cuda()
S = S.unsqueeze(0)

R = 8   # number of components
T = 400 # size of convolution window

net = NMFD(S.shape, rank=R, T=T).cuda()
# run extremely fast on gpu
net.fit(S)      # fit to target matrix S
V = net()
print(kl_div(V, S))        # KL divergence to S

A more detailed version can be found here. See our documentation to find out more usage of this package.

Compare to sklearn

The barchart shows the time cost per iteration with different beta-divergence. It shows that pytorch-based NMF has a much more constant process time across different beta values, which can take advantage when beta is not 0, 1, or 2. This is because our implementation use the same computational graph regardless which beta-divergence are we minimizing. It runs even faster when computation is done on GPU. The test is conducted on a Acer E5 laptop with i5-7200U CPU and GTX 950M GPU.

Installation

pip install torchnmf

Requirements

  • PyTorch
  • tqdm

Tips

  • If you notice significant slow down when operating on CPU, please flush denormal numbers by torch.set_flush_denormal(True).

TODO

  • Support sparse matrix target (only on NMF module).
  • Regularization.
  • NNDSVD initialization.
  • 2/3-D deconvolutional module.
  • PLCA.
  • Documentation.
  • ipynb examples.
  • Refactor PLCA module.

评论

暂无评论