-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hande Gözükan <[email protected]> Co-authored-by: Romain Primet <[email protected]>
- Loading branch information
1 parent
a4a6214
commit 1b54bac
Showing
18 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ._dicodile import dicodile | ||
|
||
__all__ = ['dicodile'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
import time | ||
import numpy as np | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from dicodile.data.images import fetch_mandrill | ||
|
||
|
||
def test_fetch_mandrill(): | ||
data = fetch_mandrill() | ||
assert(3, 512, 512) == data.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"""DiCoDiLe on the Mandrill image | ||
============================== | ||
This example illlustrates reconstruction of `Mandrill image | ||
<http://sipi.usc.edu/database/download.php?vol=misc&img=4.2.03>`_ | ||
using DiCoDiLe algorithm with default soft_lock value "border" and 9 | ||
workers. | ||
""" # noqa | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from dicodile.data.images import fetch_mandrill | ||
|
||
from dicodile.utils.dictionary import init_dictionary | ||
from dicodile.utils.viz import display_dictionaries | ||
from dicodile.utils.csc import reconstruct | ||
|
||
from dicodile import dicodile | ||
|
||
|
||
############################################################################### | ||
# We will first download the Mandrill image. | ||
|
||
X = fetch_mandrill() | ||
|
||
plt.axis('off') | ||
plt.imshow(X.swapaxes(0, 2)) | ||
|
||
|
||
############################################################################### | ||
# We will create a random dictionary of **K = 25** patches of size **8x8** | ||
# from the original Mandrill image to be used for sparse coding. | ||
|
||
# set dictionary size | ||
n_atoms = 25 | ||
|
||
# set individual atom (patch) size | ||
atom_support = (8, 8) | ||
|
||
D_init = init_dictionary(X, n_atoms, atom_support, random_state=60) | ||
|
||
############################################################################### | ||
# We are going to run `dicodile` with **9** workers on **3x3** grids. | ||
|
||
# number of iterations for dicodile | ||
n_iter = 3 | ||
|
||
# number of iterations for csc (dicodile_z) | ||
max_iter = 10000 | ||
|
||
# number of splits along each dimension | ||
w_world = 3 | ||
|
||
# number of workers | ||
n_workers = w_world * w_world | ||
|
||
# coordinate selection strategy for coordinate descent | ||
strategy = 'greedy' | ||
|
||
############################################################################### | ||
# Run `dicodile`. | ||
|
||
pobj, times, D_hat, z_hat = dicodile(X, D_init, n_iter=n_iter, | ||
n_workers=n_workers, | ||
strategy=strategy, | ||
dicod_kwargs={"max_iter": max_iter}, | ||
verbose=6) | ||
|
||
|
||
print("[DICOD] final cost : {}".format(pobj)) | ||
|
||
############################################################################### | ||
# Plot and compare the initial dictionary `D_init` with the | ||
# dictionary `D_hat` improved by `dicodile`. | ||
|
||
# normalize dictionaries | ||
normalized_D_init = D_init / D_init.max() | ||
normalized_D_hat = D_hat / D_hat.max() | ||
|
||
display_dictionaries(normalized_D_init, normalized_D_hat) | ||
|
||
|
||
############################################################################### | ||
# Reconstruct the image from `z_hat` and `D_hat`. | ||
|
||
X_hat = reconstruct(z_hat, D_hat) | ||
X_hat = np.clip(X_hat, 0, 1) | ||
|
||
|
||
############################################################################### | ||
# Plot the reconstructed image. | ||
|
||
fig = plt.figure("recovery") | ||
|
||
ax = plt.subplot() | ||
ax.imshow(X_hat.swapaxes(0, 2)) | ||
ax.axis('off') | ||
plt.tight_layout() |