Git Product home page Git Product logo

spm-image's Introduction

spm-image : Sparse modeling and Compressive sensing in Python GitHubActions

spm-image is a Python library for image analysis using sparse modeling and compressive sensing.

Requirements

  • Python 3.5 or later

Install

pip install spm-image

For developers

To set up development environment, run the following commands.

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Examples

If you want to run examples, create separated venv from one for development above.

python -m venv examples_venv
source examples_venv/bin/activate
pip install -r examples_requirements.txt

Then add it to jupyter kernels like this.

python -m ipykernel install --user --name spm-image-examples --display-name "spm-image Examples"

Thereafter, you can run jupyter notebook as follows.

jupyter notebook

Testing

You can run all test cases just like this

python -m unittest discover

Or run specific test case as follows

python -m unittest tests.test_decomposition_ksvd.TestKSVD

spm-image's People

Contributors

atusy avatar iusami avatar jakirkham avatar kitoranaoki avatar mrrmm510 avatar naoki-hacarus avatar sutkss avatar syamamori avatar takeshan avatar tksmd avatar wsuzume avatar y-iwao avatar zalgo3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spm-image's Issues

Modify ksvd inpainting example

Issue Description

From #74, masked ksvd is fixed.
We compare DCT dictionary and KSVD dictionary in this example.
In general, we cannot say that KSVD is always superior than DCT.
For example, if deficit rate is very high (i.e. 75%), then it is hard to learn dictionary, and DCT perform well.

We should prepare this kind of experiments.

Warning message is wrong in ZCA Whitening

I found wrong message in data.WhiteningScaler._fit().

                raise ValueError("""
    Eigenvalues of X' are degenerated: X'=X-np.mean(X,axis=0), \
    try normalize=True or drop_minute=True.
    """)

The above message is wrong because WhiteningScaler doesn't have normalize and drop_minute arguments. They were absorbed into thresholding argument and we should fix the code like below.

                raise ValueError("""
    Eigenvalues of X' are degenerated: X'=X-np.mean(X,axis=0), \
    try thresholding='normalize' or theresholding='drop_minute'.
    """)

Implement preconditioned primal dual algorithm for Lasso

Issue Description

implement preconditioned primal dual algorithm for lasso.
The objective function is the following:

$$|y - x|_1 + |Dx|_1$$

, where $D$ is the n-th order difference operator.

  • implement optimization algorithm
  • write unittest

References

Fix installation error regarding to requirements.txt

Fix the following error.

Collecting spm-image
  Downloading spm-image-0.0.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/tv/56_91scj52dbv6prcvl_yhsc0000gn/T/pip-build-hsk8dwhb/spm-image/setup.py", line 12, in <module>
        with Path('requirements.txt').open() as f:
      File "/Users/takashi/.pyenv/versions/3.6.3/lib/python3.6/pathlib.py", line 1161, in open
        opener=self._opener)
      File "/Users/takashi/.pyenv/versions/3.6.3/lib/python3.6/pathlib.py", line 1015, in _opener
        return self._accessor.open(self, flags, mode)
      File "/Users/takashi/.pyenv/versions/3.6.3/lib/python3.6/pathlib.py", line 387, in wrapped
        return strfunc(str(pathobj), *args)
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

Implement a function to generate DCT dictionary

Issue Description

In general, DCT dictionary is useful for initial dictionary of dictionary learning.
Hence, we prepare a function to generate DCT dictionary.

The function should be as follows:

def generate_dct_dictionary(patch_size: int, sqrt_dict_size: int) -> np.ndarray

The shape of returned array is (sqrt_dict_size^2, patch_size*patch_size)-matrix.
A row shows an atom of a dictionary, (patch_size, patch_size) patch flatten.

Support missing_value in transform in KSVD

Issue Description

missing_value is not considered in current transform implementation. We'll support missing_value in the method so that user can easily reconstruct image with missing value.

  • Implement sparce_encode_with_mask in spmimage.decomposition.dict_learning
  • Extend transform method and call sparse_encode_with_mask when missing_value is set
  • Write test

dtype mismatches in reconstructing patches

There is a bug in feature_extraction.reconstruct_from_simple_patches_2d. It can't reconstruct when type of shape argument is Tuple[int, int, int], even though extract_simple_patches_2d seems to be working correctly in case of being given the same type.

modify extract_simple_patches_2d and reconstruct_from_simple_patches_2d

Issue Description

extract_simple_patches_2d and reconstruct_from_simple_patches_2d can not support patches with overlapping. In some cases, overlapping patches is useful.
Hence, we introduce an integer parameter extraction_step, and modify these two functions.

  • modify extract_simple_patches
  • modify reconstruct_from_simple_patches_2d
  • modify unittest

Implement alert when a dictionary is not normalized

Issue Description

In spmimage.decomposition.dict_learning, some algorithms such as OMP and MP requires dictionaries to have normalized rows.
We implement alert that works if they are not normalized.

  • Add alert
  • Write unittest

Apply a hotfix to require scikit-learn>=0.19.0,<0.23.0

Issue Description

As spm-image 0.0.9 does not support sklearn >= 0.24.0 (cf. #92), we need to release a hot-fix so to require scikit-learn>=0.19.0,<0.24.0 for now.

  • Create a hotfix branch and update requirements.txt to require scikit-learn>=0.19.0,<0.24.0
  • Increment version to 0.0.10 in __init__.py
  • Merge hotfix to master
  • Release master
  • Merge hotfix to develop

Replace joblib dependency from `sklearn.externals` to `joblib` directly

Issue Description

Since joblib will be removed in sklearn 0.23 as the following message shows, replace joblib dependency from sklearn.externals to joblib directly.

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.

References

implement ZCA Whitening

Implement ZCA Whitening with sklearn interface. We want to implement fit and other methods using SVD like PCA implementation as follows.

https://github.com/scikit-learn/scikit-learn/blob/a24c8b46/sklearn/decomposition/pca.py#L107-L564

We should follow same package structure of sklearn like spmimage.decomposition.whitening.py. Within the module, implement WhiteningScaler class.

WhiteningScaler should have 'apply_zca' augment. If apply_zca equals False, WhiteningScaler should just do whitening transformation, not ZCA Whitening, and it acts like PCA implementation of sklearn.

dictionary should be normalized in _ksvd in

Issue Description

In sparse coding step in ksvd algorithm, current dictionary must be normalized.
However, it is not guaranteed at initial dictionary.
I think we need to put normalize function after initialization of dictionary of _ksvd() in decomposition/ksvd.py.

Enable initialize dictionary for ksvd algorithm

Issue Description

Right now, ksvd algorithm cannot receive initial dictionary. Only warm start is available.
However, sometimes, Starting from DCT dictionary will reduce the iteration to achieve minimizing cost function. And, it will also effective high missing ratio image inpainting (> 70% missing).

Hence, we add an option to give an initial dictionary when we make a KSVD instance.

Change library name to "rarus"

Issue Description

Though our name spm-image sounds like library for image operation, this can be used for various use case like trend filtering other than image data. Not to limit the use case and to include sparse in its name, change the library name to rarus that means sparse in Latin.

  • change repository name
  • change package name
  • change pip index

Fix bug of reconstruction error in masked ksvd

Issue Description

Missing values should be ignored when we calculate the reconstruction error in masked ksvd.

The following line should be fixed.
https://github.com/hacarus/spm-image/blob/development/spmimage/decomposition/ksvd.py#L64
https://github.com/hacarus/spm-image/blob/development/spmimage/decomposition/ksvd.py#L91

In test code, missing values are already ignored in calculation of the reconstruction error.
https://github.com/hacarus/spm-image/blob/development/tests/test_decomposition_ksvd.py#L146

Implement Generalized Lasso by ADMM

Implement Generalized LASSO using ADMM with sklearn interface.

Generalized Lasso provides

  • fused lasso
  • clustered lasso
  • trend filtering

You can implement fit method and reuse some other method provided by LinearModel like LassoLars implementation as follows.

https://github.com/scikit-learn/scikit-learn/blob/a24c8b464d094d2c468a16ea9f8bf8d42d949f84/sklearn/linear_model/least_angle.py#L499-L847
We should follow same package structure of sklearn like spmimage.linear_model.admm.py. Within the module, implement ADMM as LassoAdmm class.

Check Cython availability for faster execution of ADMM

Issue Description

According to lasso_admm.ipynb example, execution time of ADMM is almost 80x larger than coordinate decent. To reduce this gap, try Cython for faster execution of ADMM.

  • Try Cython for ADMM
  • compare execution time to coordinate decent ( default Lasso implementation in sklearn )

Support sklearn >= 0.24

Issue Description

With sklearn >= 0.24, from spmimage.decomposition import KSVD yields ModuleNotFoundError at

from sklearn.decomposition.dict_learning import SparseCodingMixin, sparse_encode

ValueError occurs for multi dimension target in ADMM when fit_itercept is true.

Issue Description

If fit_intercept flag is True, The below error was called in set_interept function.
This function is inheritance method from sklearn.linear_model.base.
It is problem that the coef
shape is matrix in spite of vector assumption in linear_model

This bug is happened in FusedLassoADMM too.

bug code

import numpy as np
from spmimage.linear_model import LassoADMM

X = np.eye(4)  
y = np.array([[1, 1],  
              [1, 0],  
              [0, 1],  
              [0, 0]])  
clf = LassoADMM(fit_intercept=True).fit(X, y)

Traceback (most recent call last): 
File "/Users/yamamoris/hacarus/spm-image/test.py", line 16, in <module> 
    clf = LassoADMM().fit(X, y) 
  File "/Users/yamamoris/hacarus/spm-image/spmimage/linear_model/admm.py", line 126, in fit
    self._set_intercept(X_offset, y_offset, X_scale) 
  File "/Users/yamamoris/.pyenv/versions/hacarus/lib/python3.6/site-packages/sklearn/linear_model/base.py", line 264, in _set_intercept 
    self.coef_ = self.coef_ / X_scale  
ValueError: operands could not be broadcast together with shapes (4,2) (4,)   

Add admm_path in spmimage.linear_model

Issue Description

Implement admm_path like lasso_path or lars_path in sklearn and add example code to draw path diagram in lasso_admm.ipynb

  • implement admm_path in spmimage/linear_model/admm.py
  • write unit test in tests/test_linear_model_admm.py
  • update examples/lasso_admm.ipynb example

You can create branch issue/33/admm_path from development branch.

References

Refactor tridiagonal implementation for faster execution of Generalized Lasso

Issue Description

We're still on the way to refactor the tridiagonal implementation like below.

  • Refactor the code
  • Evaluate performance implementation
  • Testing

For now, we'd like to release the implementation of TrendFiltering and QuadraticTrendFiltering and thus we'll do

  • revert changes of tridiagonal implementation in development branch
  • create a topic branch for this issue

Parallelizing ADMM

Looking at the n_targets for-loop, it appears that each k can be solved independently from other k's. Given this, it seems like there is a good opportunity to run each k in parallel from other ks. Combining this with the usage of Cython ( #35 ) and releasing the GIL, it should be possible for this to be embarrassingly parallel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.