Skip to content

Cuda implementations of dictionary learning algorithms

License

Notifications You must be signed in to change notification settings

mukheshpugal/dictlearn_gpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GPU Dictionary learning for python

Cuda implementations of dictionary learning algorithms. This project was inspired by the dictlearn python library.

Install

  1. This package requires Python 3+ installed. You can install it from the official website (https://www.python.org/downloads/)
  2. This package also requires nvcc to be installed and requires it to be in PATH.
  3. Install this package with python3 -m pip install git+https://github.com/mukheshpugal/dictlearn_gpu.git@master

Usage

Use this module as follows:

High level API

Train a dictionary

from dictlearn_gpu import train_dict
from dictlearn_gpu.utils import dct_dict_1d

signals = ... # Load signals. Shape == (L, N)

dictionary = dct_dict_1d(
    n_atoms=32,
    size=L,
)

new_dictionary, errors, iters = train_dict(signals, dictionary, sparsity_target=8)

Low level API

OMP-batch

import numpy as np

from dictlearn_gpu import OmpBatch
from dictlearn_gpu.utils import dct_dict_1d

signals = ... # Load signals

dictionary = dct_dict_1d(
    n_atoms=32,
    size=16,
)
ob = OmpBatch(n_atoms=32, sparsity_target=8, batch_size=2048)
decomp = ob.omp_batch(a_0=dictionary.T @ signals, gram=dictionary.T @ dictionary)

print(np.sum((signals - dictionary.dot(decomp)) ** 2))  # Reconstruction error

MOD

from dictlearn_gpu import update_dict_mod

signals = ... # Load signals
decomp = ... # Sparse decomposition

updated_dictionary = update_dict_mod(signals, decomp)

Performance analysis

Functionalities of this module were tested against equivalents from the python libraries dictlearn and sklearn. The following results are obtained:

Training on 1 dimensional signals

Training time Training loss
1D train time 1D train loss

Training on 2 dimensional signals

Training time Training loss
2D train time Screenshot (8)

About

Cuda implementations of dictionary learning algorithms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published