Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements, mainly related to cleaning up example scripts #379

Merged
merged 70 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
e436660
Trivial edit
bwohlberg Dec 17, 2022
70df967
Make related examples more consistent
bwohlberg Dec 17, 2022
b54ff55
Add support for non-blind DnCNN to functional/prox version
bwohlberg Dec 17, 2022
eb9e1cd
New example script
bwohlberg Dec 17, 2022
ba70a1a
Add new example to index
bwohlberg Dec 17, 2022
1ec5143
Trivial edits
bwohlberg Dec 17, 2022
52b0397
Merge branch 'main' into brendt/examples
bwohlberg Jan 2, 2023
36d5490
Docs improvements
bwohlberg Jan 4, 2023
dcd1639
Fix examples index
bwohlberg Jan 4, 2023
15204d9
New example script
bwohlberg Jan 4, 2023
dd59091
Minor docs change
bwohlberg Jan 4, 2023
c41fd65
Add reference to related example
bwohlberg Jan 4, 2023
d51d380
Change variable names for consistency with companion example
bwohlberg Jan 4, 2023
dfa7716
Improve docs
bwohlberg Jan 4, 2023
0308a0b
Update index
bwohlberg Jan 4, 2023
40a68b5
Fix docs
bwohlberg Jan 4, 2023
a374e1f
Typo fix
bwohlberg Jan 4, 2023
5954dba
Significant implementation change
bwohlberg Jan 4, 2023
4ae1a2e
Update index
bwohlberg Jan 4, 2023
59f34b3
Docs fix
bwohlberg Jan 4, 2023
40250b7
Improve parameters
bwohlberg Jan 4, 2023
85c31da
New tuning script, possibly temporary
bwohlberg Jan 11, 2023
4abff5c
Merge branch 'main' into brendt/examples
bwohlberg Jan 14, 2023
1c221b8
Remove now-unnecessary workaround
bwohlberg Jan 14, 2023
22c9a40
Improve docs
Jan 19, 2023
6c24e3a
Switch to standard DnCNN
Jan 19, 2023
eb5a1d9
Fix include path
Jan 19, 2023
a626e22
Minor edits
Jan 19, 2023
fe2e6b2
Update submodule
Jan 19, 2023
5438114
Remove bm4d warning
Jan 19, 2023
23a01f3
Add a plot
bwohlberg Jan 20, 2023
2b78d22
Merge branch 'main' into brendt/examples
bwohlberg Jan 24, 2023
a2e48d8
Remove temporary tuning script (no longer relevant to primary script)
Jan 26, 2023
cdadb10
Change example title
Jan 26, 2023
dab55fb
Update submodule
Jan 26, 2023
babb78e
Update submodule
Jan 27, 2023
c700990
Trivial edit
bwohlberg Jan 29, 2023
3a479f4
Explicitly set no timeout
bwohlberg Jan 29, 2023
eb62bf6
Avoid errors when list of iterations is empty
bwohlberg Jan 30, 2023
06fa55b
Bump some version requirements
bwohlberg Jan 30, 2023
2da87df
Typo fix
bwohlberg Jan 30, 2023
f151cf4
Fix parameters
bwohlberg Jan 31, 2023
2f74248
Edits for style compliance
bwohlberg Feb 1, 2023
d5f6e97
Update submodule
bwohlberg Feb 1, 2023
65a26d7
Edits for style compliance
bwohlberg Feb 1, 2023
22df675
Update submodule
bwohlberg Feb 1, 2023
9935613
Add note on example runtime
bwohlberg Feb 1, 2023
328a651
Rename include file
bwohlberg Feb 1, 2023
39782d6
Add upper bound on sphinx version due to logo/favicon bug in 6.x
bwohlberg Feb 2, 2023
ceb1cd6
Typo fix
bwohlberg Feb 2, 2023
bb68635
Robust choice of threshold
bwohlberg Feb 2, 2023
2837fa3
Avoid problems on wayland
bwohlberg Feb 2, 2023
fd3f77e
More targeted warning supression
bwohlberg Feb 2, 2023
e49d88a
Bump jax version upper bounds
Feb 2, 2023
e898cbb
Update gpu installation instructions
Feb 2, 2023
6df7f37
Minor changes
Feb 2, 2023
8a26f74
Bump required pyabel version
Feb 2, 2023
54dadb6
Robust choice of threshold
Feb 3, 2023
7933313
Update jax array type to resolve doctest failure
bwohlberg Feb 3, 2023
5fb24ca
Trivial edit
bwohlberg Feb 4, 2023
920ba5c
Add some tests
bwohlberg Feb 4, 2023
6f72992
Improve parameter search range
bwohlberg Feb 4, 2023
c71219f
Improve parameters
bwohlberg Feb 4, 2023
61a3072
Improve parameter search range
bwohlberg Feb 4, 2023
90fbaca
Improve parameters
bwohlberg Feb 4, 2023
ff11d9c
Update submodule
bwohlberg Feb 4, 2023
e78340a
Bump copyright year of modified files
bwohlberg Feb 4, 2023
54161eb
Docstring fix
bwohlberg Feb 6, 2023
d064e45
Update submodule
bwohlberg Feb 6, 2023
fd46f3d
Improve jax installation instructions
bwohlberg Feb 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-r ../requirements.txt
sphinx>=4.2.0
sphinx>=4.2.0,<=5.3.0
sphinxcontrib-napoleon
sphinxcontrib-bibtex
sphinx-autodoc-typehints
faculty-sphinx-theme
jinja2<3.1.0 # temporary fix for jina2/nbconvert bug
jinja2<3.1.0 # temporary fix for jinja2/nbconvert bug
traitlets!=5.2.2 # temporary fix for ipython/traitlets#741
nbsphinx
ipython_genutils
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def patched_parse(self):

# General information about the project.
project = "SCICO"
copyright = "2020-2022, SCICO Developers"
copyright = "2020-2023, SCICO Developers"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
8 changes: 7 additions & 1 deletion docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Usage Examples
.. toctree::
:maxdepth: 1

.. include:: include/exampledepend.rst
.. include:: include/examplenotes.rst


Organized by Application
Expand Down Expand Up @@ -43,12 +43,14 @@ Deconvolution

examples/deconv_circ_tv_admm
examples/deconv_tv_admm
examples/deconv_tv_padmm
examples/deconv_tv_admm_tune
examples/deconv_microscopy_tv_admm
examples/deconv_microscopy_allchn_tv_admm
examples/deconv_ppp_bm3d_admm
examples/deconv_ppp_bm3d_pgm
examples/deconv_ppp_dncnn_admm
examples/deconv_ppp_dncnn_padmm
examples/deconv_ppp_bm4d_admm
examples/deconv_modl_train_foam1
examples/deconv_odp_train_foam1
Expand Down Expand Up @@ -105,6 +107,7 @@ Plug and Play Priors
examples/deconv_ppp_bm3d_admm
examples/deconv_ppp_bm3d_pgm
examples/deconv_ppp_dncnn_admm
examples/deconv_ppp_dncnn_padmm
examples/deconv_ppp_bm4d_admm
examples/demosaic_ppp_bm3d_admm
examples/superres_ppp_dncnn_admm
Expand All @@ -123,6 +126,7 @@ Total Variation
examples/deconv_circ_tv_admm
examples/deconv_tv_admm
examples/deconv_tv_admm_tune
examples/deconv_tv_padmm
examples/deconv_microscopy_tv_admm
examples/deconv_microscopy_allchn_tv_admm
examples/denoise_l1tv_admm
Expand Down Expand Up @@ -216,8 +220,10 @@ Proximal ADMM
.. toctree::
:maxdepth: 1

examples/deconv_tv_padmm
examples/denoise_tv_multi
examples/denoise_cplx_tv_nlpadmm
examples/deconv_ppp_dncnn_padmm


Non-linear Proximal ADMM
Expand Down
19 changes: 0 additions & 19 deletions docs/source/include/exampledepend.rst

This file was deleted.

32 changes: 32 additions & 0 deletions docs/source/include/examplenotes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _example_depend:

Example Dependencies
--------------------

Some examples use additional dependencies, which are listed in `examples_requirements.txt <https://github.com/lanl/scico/blob/main/examples/examples_requirements.txt>`_.
The additional requirements should be installed via pip, with the exception of ``astra-toolbox``,
which should be installed via conda:

::

conda install -c astra-toolbox astra-toolbox
pip install -r examples/examples_requirements.txt # Installs other example requirements

The dependencies can also be installed individually as required.

Note that ``astra-toolbox`` should be installed on a host with one or more CUDA GPUs to ensure
that the version with GPU support is installed.


Run Time
--------

Most of these examples have been constructed with sufficiently small test problems to
allow them to run to completion within 5 minutes or less on a reasonable workstation.
Note, however, that it was not feasible to construct meaningful examples of the training
of some of the deep learning algorithms that complete within a relatively short time;
the examples "CT Training and Reconstructions with MoDL" and "CT Training and
Reconstructions with ODP" in particular are much slower, and can require multiple hours
to run on a workstation with multiple GPUs.

|
16 changes: 10 additions & 6 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ The instructions above install a CPU-only version of SCICO. To install a version

1. Follow the CPU only instructions, above

2. Identify which version of jaxlib was installed
2. Install the version of jaxlib with GPU support, as described in the `JAX installation
instructions <https://github.com/google/jax#installation>`_.
In the simplest case, the appropriate command is

::

pip list | grep jaxlib
pip install -upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

3. Install the same version of jaxlib, but with GPU support.
For help with this, see `JAX with GPU support <https://github.com/google/jax#installation>`_.
The command will be something like

but it may be necessary to explicitly specify the ``jaxlib`` version if the most recent release is not yet
supported by SCICO (as specified in the ``requirements.txt`` file), or if using a version of CUDA older
than 11.4, or CuDNN older than 8.2, in which case the command would be of the form
::

pip install --upgrade "jaxlib==0.3.0+cuda11.cudnn805" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
pip install -upgrade "jaxlib==0.4.2+cuda11.cudnn82" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

with appropriate substitution of ``jaxlib``, CUDA, and CuDNN version numbers.



Expand Down
4 changes: 2 additions & 2 deletions examples/jnb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 by SCICO Developers
# Copyright (C) 2022-2023 by SCICO Developers
# All rights reserved. BSD 3-clause License.
# This file is part of the SCICO package. Details of the copyright and
# user license can be found in the 'LICENSE' file distributed with the
Expand Down Expand Up @@ -100,7 +100,7 @@ def execute_notebook(fname):

with open(fname) as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor()
ep = ExecutePreprocessor(timeout=None)
try:
t0 = timer()
out = ep.preprocess(nb)
Expand Down
2 changes: 1 addition & 1 deletion examples/makenotebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def notebook_path(sname):
argparser.add_argument(
"--all",
action="store_true",
help="Process all notebooks, without checking timestamps. "
help="Process all notebooks, without checking timestamps. "
"Has no effect when files to process are explicitly specified.",
)
argparser.add_argument(
Expand Down
18 changes: 2 additions & 16 deletions examples/scriptcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,12 @@ if [ ! $# -eq 0 ] ; then
exit 2
fi

# Check for presence of Xvfb tool which is used to avoid plots being displayed.
if [ ! "$(which Xvfb 2>/dev/null)" ]; then
msg="Warning: required tool Xvfb not found: functionality will be degraded"
echo $msg >&2
pid=0
else
Xvfb :20 -screen 0 800x600x16 > /dev/null 2>&1 &
pid=$!
export DISPLAY=:20.0
fi

# Set environment variables and paths. This script is assumed to be run
# from its root directory.
export PYTHONPATH=$SCRIPTPATH/..
export PYTHONIOENCODING=utf-8
export MPLBACKEND=agg
export PYTHONWARNINGS=ignore:Matplotlib:UserWarning
d='/tmp/scriptcheck_'$$
mkdir -p $d
retval=0
Expand Down Expand Up @@ -117,9 +108,4 @@ done
# Remove temporary script directory.
rmdir $d

# Kill Xvfb process if it was started.
if [ $pid != 0 ]; then
kill $pid
fi

exit $retval
42 changes: 35 additions & 7 deletions examples/scripts/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Deconvolution
`deconv_circ_tv_admm.py <deconv_circ_tv_admm.py>`_
Circulant Blur Image Deconvolution with TV Regularization
`deconv_tv_admm.py <deconv_tv_admm.py>`_
Image Deconvolution with TV Regularization
Image Deconvolution with TV Regularization (ADMM Solver)
`deconv_tv_padmm.py <deconv_tv_padmm.py>`_
Image Deconvolution with TV Regularization (Proximal ADMM Solver)
`deconv_tv_admm_tune.py <deconv_tv_admm_tune.py>`_
Image Deconvolution Parameter Tuning
`deconv_microscopy_tv_admm.py <deconv_microscopy_tv_admm.py>`_
Expand All @@ -51,7 +53,9 @@ Deconvolution
`deconv_ppp_bm3d_pgm.py <deconv_ppp_bm3d_pgm.py>`_
PPP (with BM3D) Image Deconvolution (APGM Solver)
`deconv_ppp_dncnn_admm.py <deconv_ppp_dncnn_admm.py>`_
PPP (with DnCNN) Image Deconvolution
PPP (with DnCNN) Image Deconvolution (ADMM Solver)
`deconv_ppp_dncnn_padmm.py <deconv_ppp_dncnn_padmm.py>`_
PPP (with DnCNN) Image Deconvolution (Proximal ADMM Solver)
`deconv_ppp_bm4d_admm.py <deconv_ppp_bm4d_admm.py>`_
PPP (with BM4D) Volume Deconvolution
`deconv_modl_train_foam1.py <deconv_modl_train_foam1.py>`_
Expand Down Expand Up @@ -121,7 +125,9 @@ Plug and Play Priors
`deconv_ppp_bm3d_pgm.py <deconv_ppp_bm3d_pgm.py>`_
PPP (with BM3D) Image Deconvolution (APGM Solver)
`deconv_ppp_dncnn_admm.py <deconv_ppp_dncnn_admm.py>`_
PPP (with DnCNN) Image Deconvolution
PPP (with DnCNN) Image Deconvolution (ADMM Solver)
`deconv_ppp_dncnn_padmm.py <deconv_ppp_dncnn_padmm.py>`_
PPP (with DnCNN) Image Deconvolution (Proximal ADMM Solver)
`deconv_ppp_bm4d_admm.py <deconv_ppp_bm4d_admm.py>`_
PPP (with BM4D) Volume Deconvolution
`demosaic_ppp_bm3d_admm.py <demosaic_ppp_bm3d_admm.py>`_
Expand All @@ -144,9 +150,11 @@ Total Variation
`deconv_circ_tv_admm.py <deconv_circ_tv_admm.py>`_
Circulant Blur Image Deconvolution with TV Regularization
`deconv_tv_admm.py <deconv_tv_admm.py>`_
Image Deconvolution with TV Regularization
Image Deconvolution with TV Regularization (ADMM Solver)
`deconv_tv_admm_tune.py <deconv_tv_admm_tune.py>`_
Image Deconvolution Parameter Tuning
`deconv_tv_padmm.py <deconv_tv_padmm.py>`_
Image Deconvolution with TV Regularization (Proximal ADMM Solver)
`deconv_microscopy_tv_admm.py <deconv_microscopy_tv_admm.py>`_
Deconvolution Microscopy (Single Channel)
`deconv_microscopy_allchn_tv_admm.py <deconv_microscopy_allchn_tv_admm.py>`_
Expand Down Expand Up @@ -228,7 +236,7 @@ ADMM
`deconv_circ_tv_admm.py <deconv_circ_tv_admm.py>`_
Circulant Blur Image Deconvolution with TV Regularization
`deconv_tv_admm.py <deconv_tv_admm.py>`_
Image Deconvolution with TV Regularization
Image Deconvolution with TV Regularization (ADMM Solver)
`deconv_tv_admm_tune.py <deconv_tv_admm_tune.py>`_
Image Deconvolution Parameter Tuning
`deconv_microscopy_tv_admm.py <deconv_microscopy_tv_admm.py>`_
Expand All @@ -238,7 +246,7 @@ ADMM
`deconv_ppp_bm3d_admm.py <deconv_ppp_bm3d_admm.py>`_
PPP (with BM3D) Image Deconvolution (ADMM Solver)
`deconv_ppp_dncnn_admm.py <deconv_ppp_dncnn_admm.py>`_
PPP (with DnCNN) Image Deconvolution
PPP (with DnCNN) Image Deconvolution (ADMM Solver)
`deconv_ppp_bm4d_admm.py <deconv_ppp_bm4d_admm.py>`_
PPP (with BM4D) Volume Deconvolution
`sparsecode_admm.py <sparsecode_admm.py>`_
Expand Down Expand Up @@ -266,6 +274,26 @@ Linearized ADMM
Comparison of Optimization Algorithms for Total Variation Denoising


Proximal ADMM
^^^^^^^^^^^^^

`deconv_tv_padmm.py <deconv_tv_padmm.py>`_
Image Deconvolution with TV Regularization (Proximal ADMM Solver)
`denoise_tv_multi.py <denoise_tv_multi.py>`_
Comparison of Optimization Algorithms for Total Variation Denoising
`denoise_cplx_tv_nlpadmm.py <denoise_cplx_tv_nlpadmm.py>`_
Complex Total Variation Denoising with NLPADMM Solver
`deconv_ppp_dncnn_padmm.py <deconv_ppp_dncnn_padmm.py>`_
PPP (with DnCNN) Image Deconvolution (Proximal ADMM Solver)


Non-linear Proximal ADMM
^^^^^^^^^^^^^^^^^^^^^^^^

`denoise_cplx_tv_nlpadmm.py <denoise_cplx_tv_nlpadmm.py>`_
Complex Total Variation Denoising with NLPADMM Solver


PDHG
^^^^

Expand All @@ -274,7 +302,7 @@ PDHG
`denoise_tv_multi.py <denoise_tv_multi.py>`_
Comparison of Optimization Algorithms for Total Variation Denoising
`denoise_cplx_tv_pdhg.py <denoise_cplx_tv_pdhg.py>`_
Complex Total Variation Denoising
Complex Total Variation Denoising with PDHG Solver


PGM
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/ct_abel_tv_admm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"""
Set up ADMM solver object.
"""
λ = 1.9e1 # L1 norm regularization parameter
ρ = 4.9e1 # ADMM penalty parameter
λ = 2.9e1 # L1 norm regularization parameter
ρ = 8.5e1 # ADMM penalty parameter
maxiter = 100 # number of ADMM iterations
cg_tol = 1e-4 # CG relative tolerance
cg_maxiter = 25 # maximum CG iterations per ADMM iteration
Expand Down
35 changes: 34 additions & 1 deletion examples/scripts/ct_abel_tv_admm_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def eval_params(config, reporter):
"""
Define parameter search space and resources per trial.
"""
config = {"lambda": tune.loguniform(1e-2, 1e3), "rho": tune.loguniform(1e-1, 1e3)}
config = {"lambda": tune.loguniform(1e0, 1e2), "rho": tune.loguniform(1e1, 1e3)}
resources = {"gpu": 0, "cpu": 1} # gpus per trial, cpus per trial


Expand Down Expand Up @@ -165,4 +165,37 @@ def eval_params(config, reporter):
fig.show()


"""
Plot parameter values visited during parameter search and corresponding
reconstruction PSNRs.The best point in the parameter space is indicated
in red.
"""
𝜌 = [t.config["rho"] for t in analysis.trials]
𝜆 = [t.config["lambda"] for t in analysis.trials]
psnr = [t.metric_analysis["psnr"]["max"] for t in analysis.trials]
minpsnr = min(max(psnr), 20.0)
𝜌, 𝜆, psnr = zip(*filter(lambda x: x[2] >= minpsnr, zip(𝜌, 𝜆, psnr)))
fig, ax = plot.subplots(figsize=(10, 8))
sc = ax.scatter(𝜌, 𝜆, c=psnr, cmap=plot.cm.plasma_r)
fig.colorbar(sc)
plot.plot(
best_config["lambda"],
best_config["rho"],
ptyp="loglog",
lw=0,
ms=12.0,
marker="2",
mfc="red",
mec="red",
fig=fig,
ax=ax,
)
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_xlabel(r"$\rho$")
ax.set_ylabel(r"$\lambda$")
ax.set_title("PSNR at each sample location\n(values below 20 dB omitted)")
fig.show()


input("\nWaiting for input to close figures and exit")
Loading