Skip to content

Commit

Permalink
Clean up examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Apr 25, 2023
1 parent a84dbab commit e522bef
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 57 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ install the library locally.
python scripts/recon/admm.py
Note (25-04-2023): for using the Pycsou models V2 has to be installed:
Note (25-04-2023): for using reconstruction method based on Pycsou ``lensless.apgd.APGD``,
V2 has to be installed:

.. code:: bash
Expand Down
29 changes: 0 additions & 29 deletions configs/apgd_thumbs_up.yaml

This file was deleted.

17 changes: 16 additions & 1 deletion configs/defaults_recon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ admm:
mu1: 1e-6
mu2: 1e-5
mu3: 4e-5
tau: 0.0001
tau: 0.0001

apgd:
# Stopping criteria
max_iter: 1000
rel_error: 1e-6
acceleration: True
# Differentiable prior / regularization: l2, null
diff_penalty: null
diff_lambda: 0.001
# Proximal prior / regularization: nonneg, l1, null
prox_penalty: nonneg
prox_lambda: 0.001
# Lipschitz
lipschitz_tight: True
lipschitz_tol: 1.0
22 changes: 15 additions & 7 deletions lensless/apgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ def __init__(
dtype=np.float32,
diff_penalty=None,
prox_penalty=APGDPriors.NONNEG,
acceleration="BT",
acceleration=True,
diff_lambda=0.001,
prox_lambda=0.001,
disp=100,
rel_error=1e-6,
lipschitz_tight=True,
lipschitz_tol=1.0,
**kwargs
):
"""
Expand All @@ -143,15 +145,20 @@ def __init__(
Proximal functional to serve as prior / regularization term. Default
is non-negative prior. See `Pycsou documentation <https://matthieumeo.github.io/pycsou/html/api/functionals/pycsou.func.penalty.html?highlight=penalty#module-pycsou.func.penalty>`__
for available penalties.
acceleration : [None, 'BT', 'CD']
Which acceleration scheme should be used (None for no acceleration).
"BT" (Beck and Teboule) has convergence `O(1/k^2)`, while "CD"
(Chambolle and Dossal) has convergence `o(1/K^2)`. So "CD" should be
faster. but from our experience "BT" gives better results.
acceleration : bool, optional
Whether to use acceleration or not. Default is True.
diff_lambda : float
Weight of differentiable penalty.
prox_lambda : float
Weight of proximal penalty.
disp : int, optional
Display frequency. Default is 100.
rel_error : float, optional
Relative error to stop optimization. Default is 1e-6.
lipschitz_tight : bool, optional
Whether to use tight Lipschitz constant or not. Default is True.
lipschitz_tol : float, optional
Tolerance to compute Lipschitz constant. Default is 1.
"""

# PSF and data are the same size / shape
Expand All @@ -168,6 +175,7 @@ def __init__(

# Convolution operator
self._H = RealFFTConvolve2D(self._psf, dtype=dtype)
self._H.lipschitz(tol=lipschitz_tol, tight=lipschitz_tight)

# initialize solvers which will be created when data is set
if diff_penalty is not None:
Expand Down Expand Up @@ -229,7 +237,7 @@ def set_data(self, data):
stop_crit=self._stop_crit,
track_objective=True,
mode=pyca.solver.Mode.MANUAL,
acceleration=True,
acceleration=self._acc,
)

def reset(self):
Expand Down
9 changes: 1 addition & 8 deletions scripts/recon/admm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import time
import pathlib as plib
import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np
from lensless.io import load_data
from lensless import ADMM
Expand Down Expand Up @@ -48,13 +47,7 @@ def admm(config):
save = os.getcwd()

start_time = time.time()
recon = ADMM(
psf,
mu1=config["admm"]["mu1"],
mu2=config["admm"]["mu2"],
mu3=config["admm"]["mu3"],
tau=config["admm"]["tau"],
)
recon = ADMM(psf, **config.admm)
recon.set_data(data)
print(f"Setup time : {time.time() - start_time} s")

Expand Down
13 changes: 3 additions & 10 deletions scripts/recon/apgd_pycsou.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
log = logging.getLogger(__name__)


@hydra.main(version_base=None, config_path="../../configs", config_name="apgd_thumbs_up")
@hydra.main(version_base=None, config_path="../../configs", config_name="defaults_recon")
def apgd(
config,
):

psf, data = load_data(
psf_fp=to_absolute_path(config["input"]["psf"]),
data_fp=to_absolute_path(config["input"]["data"]),
dtype=config.input.dtype,
downsample=config["preprocess"]["downsample"],
bayer=config["preprocess"]["bayer"],
blue_gain=config["preprocess"]["blue_gain"],
Expand All @@ -58,15 +59,7 @@ def apgd(
save = os.getcwd()

start_time = time.time()
recon = APGD(
psf=psf,
max_iter=config["apgd"]["max_iter"],
acceleration=config["apgd"]["acceleration"],
diff_penalty=config["apgd"]["diff_penalty"],
diff_lambda=config["apgd"]["diff_lambda"],
prox_penalty=config["apgd"]["prox_penalty"],
prox_lambda=config["apgd"]["prox_lambda"],
)
recon = APGD(psf=psf, **config.apgd)
recon.set_data(data)
print(f"Setup time : {time.time() - start_time} s")

Expand Down
1 change: 0 additions & 1 deletion scripts/recon/gradient_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import numpy as np
import time
import pathlib as plib
from datetime import datetime
import matplotlib.pyplot as plt
from lensless.io import load_data
from lensless import (
Expand Down

0 comments on commit e522bef

Please sign in to comment.