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

Adding new reconstruction methods and exposing different parameters for PSF simulation. #133

Merged
merged 66 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
07cf6bb
Add full digicam example.
ebezzam Feb 28, 2024
a97c1df
Merge branch 'main' into digicam_example
ebezzam Apr 25, 2024
ced618a
Update digicam config.
ebezzam Apr 26, 2024
f449fb7
Clean up digicam example.
ebezzam May 15, 2024
e30b5db
Setting relative path.
ebezzam May 15, 2024
0359a33
Set image resolution remotely.
ebezzam May 15, 2024
709dbed
Add checks that are in on-device script.
ebezzam May 15, 2024
6725dd8
Add options for background image.
ebezzam May 16, 2024
96a29d1
Merge branch 'main' into digicam_example
ebezzam May 16, 2024
742bdde
Update CHANGELOG.
ebezzam May 25, 2024
a5f6edf
Expose PSF simulation parameters, ensure RGB for training.
ebezzam May 25, 2024
b72b959
Merge branch 'main' into expose_sim_param
ebezzam May 25, 2024
9026651
Merge branch 'main' into digicam_example
ebezzam May 27, 2024
3ebfeff
Improve analyze image script.
ebezzam May 27, 2024
a111135
Merge branch 'digicam_example' into expose_sim_param
ebezzam May 27, 2024
6204ff4
Use waveprop param.
ebezzam May 27, 2024
75719e6
Merge branch 'expose_sim_param' of github.com:LCAV/LenslessPiCam into…
ebezzam May 27, 2024
f391830
Expose more simulation parameters, add options to simulate lensless.
ebezzam Jun 5, 2024
0a3d539
Remove metric reduction in batches.
ebezzam Jun 5, 2024
7d33a30
Remove reduction on batch dim.
ebezzam Jun 5, 2024
2b99c55
Add option to benchmark HF models.
ebezzam Jun 5, 2024
cafca66
Add example config for benchmarking HF model.
ebezzam Jun 5, 2024
2685ec3
FIx multilens array centering and expose focal length.
ebezzam Jun 5, 2024
515f62f
Add compensation branch option.
ebezzam Jun 9, 2024
3193b60
Upload viewable version of 16 bits files.
ebezzam Jun 9, 2024
ef6e9c0
Add option to skip pre and post proc, and multi Wiener filter.
ebezzam Jun 11, 2024
b1ad3a7
Add support for preproc aux and initializing from HF model.
ebezzam Jun 14, 2024
26e860d
Add preproc support for multi-wiener, add single psf option for bench…
ebezzam Jun 18, 2024
9afc864
Add support for single channel and flipping.
ebezzam Jun 19, 2024
e72aa11
Add residual block to compensation.
ebezzam Jun 27, 2024
9c2da9c
Add option for passing PSF.
ebezzam Jul 1, 2024
aab3e09
Add residual to compensation branch, flipping option for augmentation…
ebezzam Jul 5, 2024
6ffaad2
Add gamma correction option.
ebezzam Jul 5, 2024
582cdd8
Merge branch 'expose_sim_param' of github.com:LCAV/LenslessPiCam into…
ebezzam Jul 5, 2024
6f2ff1e
Add perlin numpy.
Jul 5, 2024
c0124a4
Add models, optional background subtraction.
ebezzam Jul 9, 2024
8a16f4d
Merge branch 'main' into expose_sim_param
ebezzam Jul 9, 2024
c54097a
Remove mask config.
ebezzam Jul 9, 2024
4d97665
Fix test.
ebezzam Jul 9, 2024
21cc3de
Fix test.
ebezzam Jul 9, 2024
f8bb65c
Remove FISTA to see test.
ebezzam Jul 9, 2024
3ce077b
Update numpy.
ebezzam Jul 9, 2024
817b254
Fix multimask for random flips.
ebezzam Jul 9, 2024
b962a7b
Support for AdamW and linearly decay learning rate.
ebezzam Jul 9, 2024
7cace0e
Add exp decay of learning rate.
ebezzam Jul 9, 2024
10d3bd9
Merge branch 'main' into expose_sim_param
ebezzam Jul 9, 2024
f31d7ae
Add cosine decay learning rate schedule.
ebezzam Jul 9, 2024
8b434db
Add option for random rotations.
ebezzam Jul 10, 2024
767be7d
Add option of when to update LR.
ebezzam Jul 10, 2024
3e37c75
Merge branch 'expose_sim_param' of github.com:LCAV/LenslessPiCam into…
ebezzam Jul 10, 2024
fd13dce
Add diffusercam benchmark config.
ebezzam Jul 10, 2024
25890e0
Add option to initialize with full model.
ebezzam Jul 11, 2024
230af02
Add function for setting PSF, add extra dimension when single image.
ebezzam Jul 11, 2024
4d8cd85
Add option to train on simulated, and test on measured.
ebezzam Jul 11, 2024
3a4b57d
Add option to fine-tune just last layer.
ebezzam Jul 15, 2024
f0cc3af
Add option to reconstruct single image.
ebezzam Jul 15, 2024
c524d2b
Add support for simulated multimask.
ebezzam Jul 15, 2024
5263765
Remove need for alignment in extract function.
ebezzam Jul 16, 2024
937a59c
Add noise, fix return for extract roi.
ebezzam Jul 16, 2024
ee1e221
Update demo.
ebezzam Jul 21, 2024
d0f9f8e
Merge branch 'expose_sim_param' of github.com:LCAV/LenslessPiCam into…
ebezzam Jul 21, 2024
2a5f5ac
Specify setup file.
ebezzam Jul 22, 2024
34ed92c
Add shifting and fixes for MMCN and MWDN inference.
ebezzam Jul 31, 2024
7d129ef
Add new configs.
ebezzam Jul 31, 2024
b27b973
Clean up files and update CHANGELOG.
ebezzam Aug 7, 2024
b797160
Formatting.
ebezzam Aug 7, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/python_pycsou.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
max-parallel: 12
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-12, windows-latest]
python-version: [3.9, "3.10"]
steps:
- uses: actions/checkout@v3
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ Added

- Option to pass background image to ``utils.io.load_data``.
- Option to set image resolution with ``hardware.utils.display`` function.
- Auxiliary of reconstructing output from pre-processor (not working).
- Option to set focal range for MultiLensArray.
- Optional to remove deadspace modelling for programmable mask.
- Compensation branch for unrolled ADMM: https://ieeexplore.ieee.org/abstract/document/9546648
- Multi-Wiener deconvolution network: https://opg.optica.org/oe/fulltext.cfm?uri=oe-31-23-39088&id=541387
- Option to skip pre-processor and post-processor at inference time.
- Option to set difference learning rate schedules, e.g. ADAMW, exponential decay, Cosine decay with warmup.
- Various augmentations for training: random flipping, random rotate, and random shifts. Latter two don't work well since new regions appear that throw off PSF/LSI modeling.
- HFSimulated object for simulating lensless data from ground-truth and PSF.
- Option to set cache directory for Hugging Face datasets.
- Option to initialize training with another model.

Changed
~~~~~~~
Expand All @@ -24,7 +35,9 @@ Changed
Bugfix
~~~~~~

- Nothing
- Computation of average metric in batches.
- Support for grayscale PSF for RealFFTConvolve2D.
- Calling model.eval() before inference, and model.train() before training.


1.0.7 - (2024-05-14)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The toolkit includes:
* Camera assembly tutorials (`link <https://lensless.readthedocs.io/en/latest/building.html>`__).
* Measurement scripts (`link <https://lensless.readthedocs.io/en/latest/measurement.html>`__).
* Dataset preparation and loading tools, with `Hugging Face <https://huggingface.co/bezzam>`__ integration (`slides <https://docs.google.com/presentation/d/18h7jTcp20jeoiF8dJIEcc7wHgjpgFgVxZ_bJ04W55lg/edit?usp=sharing>`__ on uploading a dataset to Hugging Face with `this script <https://github.com/LCAV/LenslessPiCam/blob/main/scripts/data/upload_dataset_huggingface.py>`__).
* `Reconstruction algorithms <https://lensless.readthedocs.io/en/latest/reconstruction.html>`__ (e.g. FISTA, ADMM, unrolled algorithms, trainable inversion, pre- and post-processors).
* `Reconstruction algorithms <https://lensless.readthedocs.io/en/latest/reconstruction.html>`__ (e.g. FISTA, ADMM, unrolled algorithms, trainable inversion, , multi-Wiener deconvolution network, pre- and post-processors).
* `Training script <https://github.com/LCAV/LenslessPiCam/blob/main/scripts/recon/train_learning_based.py>`__ for learning-based reconstruction.
* `Pre-trained models <https://github.com/LCAV/LenslessPiCam/blob/main/lensless/recon/model_dict.py>`__ that can be loaded from `Hugging Face <https://huggingface.co/bezzam>`__, for example in `this script <https://github.com/LCAV/LenslessPiCam/blob/main/scripts/recon/diffusercam_mirflickr.py>`__.
* Mask `design <https://lensless.readthedocs.io/en/latest/mask.html>`__ and `fabrication <https://lensless.readthedocs.io/en/latest/fabrication.html>`__ tools.
Expand Down
13 changes: 12 additions & 1 deletion configs/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ hydra:

dataset: DiffuserCam # DiffuserCam, DigiCamCelebA, HFDataset
seed: 0
batchsize: 1 # must be 1 for iterative approaches

huggingface:
repo: "bezzam/DigiCam-Mirflickr-MultiMask-25K"
cache_dir: null # where to read/write dataset. Defaults to `"~/.cache/huggingface/datasets"`.
psf: null # null for simulating PSF
image_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
flipud: False
flip_lensed: False # if rotate or flipud is True, apply to lensed
alignment:
top_left: [80, 100] # height, width
height: 200
downsample: 1
downsample_lensed: 1
split_seed: null
single_channel_psf: False

device: "cuda"
# numbers of iterations to benchmark
Expand All @@ -33,6 +41,8 @@ algorithms: ["ADMM", "ADMM_Monakhova2019", "FISTA"] #["ADMM", "ADMM_Monakhova201
baseline: "MONAKHOVA 100iter"

save_idx: [0, 1, 2, 3, 4] # provide index of files to save e.g. [1, 5, 10]
gamma_psf: 1.5 # gamma factor for PSF


# Hyperparameters
nesterov:
Expand Down Expand Up @@ -86,7 +96,8 @@ simulation:
# mask2sensor: 9e-3 # mask2sensor: 4e-3
# -- for CelebA
scene2mask: 0.25 # [m]
mask2sensor: 0.002 # [m]
mask2sensor: 0.002 # [m]
deadspace: True # whether to account for deadspace for programmable mask
# see waveprop.devices
use_waveprop: False # for PSF simulation
sensor: "rpi_hq"
Expand Down
63 changes: 63 additions & 0 deletions configs/benchmark_diffusercam_mirflickr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# python scripts/eval/benchmark_recon.py -cn benchmark_diffusercam_mirflickr
defaults:
- benchmark
- _self_

dataset: HFDataset
batchsize: 4
device: "cuda:0"

huggingface:
repo: "bezzam/DiffuserCam-Lensless-Mirflickr-Dataset-NORM"
psf: psf.tiff
image_res: null
rotate: False # if measurement is upside-down
alignment: null
downsample: 2
downsample_lensed: 2
flipud: True
flip_lensed: True
single_channel_psf: True

algorithms: [
"ADMM",

## -- reconstructions trained on DiffuserCam measured
"hf:diffusercam:mirflickr:U5+Unet8M",
"hf:diffusercam:mirflickr:TrainInv+Unet8M",
"hf:diffusercam:mirflickr:MMCN4M+Unet4M",
"hf:diffusercam:mirflickr:MWDN8M",
"hf:diffusercam:mirflickr:Unet4M+U5+Unet4M",
"hf:diffusercam:mirflickr:Unet4M+TrainInv+Unet4M",
"hf:diffusercam:mirflickr:Unet2M+MMCN+Unet2M",
"hf:diffusercam:mirflickr:Unet2M+MWDN6M",
"hf:diffusercam:mirflickr:Unet4M+U10+Unet4M",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_ft_tapecam",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_ft_tapecam_post",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_ft_tapecam_pre",

# ## -- reconstruction trained on DiffuserCam simulated
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_tapecam",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_tapecam_post",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_tapecam_pre",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_digicam_multi_post",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_digicam_multi_pre",
# "hf:diffusercam:mirflickr_sim:Unet4M+U5+Unet4M_ft_digicam_multi",

# ## -- reconstructions trained on other datasets/systems
# "hf:tapecam:mirflickr:Unet4M+U10+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
# "hf:digicam:celeba_26k:Unet4M+U5+Unet4M_wave",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U10+Unet4M_wave",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M_flips",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M_flips_rotate10",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M_aux1",
# "hf:digicam:mirflickr_multi_25k:Unet4M+U10+Unet4M_wave",
# "hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave",
]

save_idx: [0, 1, 3, 4, 8, 45, 58, 63]
n_iter_range: [100] # for ADMM

62 changes: 62 additions & 0 deletions configs/benchmark_digicam_celeba.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# python scripts/eval/benchmark_recon.py -cn benchmark_digicam_celeba
defaults:
- benchmark
- _self_


dataset: HFDataset
batchsize: 10
device: "cuda:0"

algorithms: [
"ADMM",

## -- reconstructions trained on measured data
"hf:digicam:celeba_26k:U5+Unet8M_wave",
"hf:digicam:celeba_26k:TrainInv+Unet8M_wave",
"hf:digicam:celeba_26k:MWDN8M_wave",
"hf:digicam:celeba_26k:MMCN4M+Unet4M_wave",
"hf:digicam:celeba_26k:Unet2M+MWDN6M_wave",
"hf:digicam:celeba_26k:Unet4M+TrainInv+Unet4M_wave",
"hf:digicam:celeba_26k:Unet2M+MMCN+Unet2M_wave",
"hf:digicam:celeba_26k:Unet4M+U5+Unet4M_wave",
"hf:digicam:celeba_26k:Unet4M+U10+Unet4M_wave",

# # -- reconstructions trained on other datasets/systems
# "hf:diffusercam:mirflickr:Unet4M+U10+Unet4M",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M",
# "hf:tapecam:mirflickr:Unet4M+U10+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
# "hf:digicam:mirflickr_single_25k:Unet4M+U10+Unet4M_wave",
]

save_idx: [0, 2, 3, 4, 9]
n_iter_range: [100] # for ADMM

huggingface:
repo: bezzam/DigiCam-CelebA-26K
psf: psf_simulated_waveprop.png # psf_simulated_waveprop.png, psf_simulated.png, psf_measured.png
split_seed: 0
test_size: 0.15
downsample: 2
image_res: null

alignment:
top_left: null
height: null

# cropping when there is no downsampling
crop:
vertical: [0, 525]
horizontal: [265, 695]

# for prepping ground truth data
simulation:
scene2mask: 0.25 # [m]
mask2sensor: 0.002 # [m]
object_height: 0.33 # [m]
sensor: "rpi_hq"
# shifting when there is no files to downsample
vertical_shift: -117
horizontal_shift: -25
60 changes: 60 additions & 0 deletions configs/benchmark_digicam_mirflickr_multi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# python scripts/eval/benchmark_recon.py -cn benchmark_digicam_mirflickr_multi
defaults:
- benchmark
- _self_


dataset: HFDataset
batchsize: 4
device: "cuda:0"

huggingface:
repo: "bezzam/DigiCam-Mirflickr-MultiMask-25K"
psf: null # null for simulating PSF
image_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
flipud: False
flip_lensed: False # if rotate or flipud is True, apply to lensed
alignment:
top_left: [80, 100] # height, width
height: 200
downsample: 1

algorithms: [
"ADMM",

## -- reconstructions trained on measured data
"hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave",
"hf:digicam:mirflickr_multi_25k:Unet4M+U10+Unet4M_wave",
"hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave_aux1",
"hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave_flips",

# ## -- reconstructions trained on other datasets/systems
# "hf:diffusercam:mirflickr:Unet4M+U10+Unet4M",
# "hf:tapecam:mirflickr:Unet4M+U10+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U10+Unet4M_wave",
# "hf:digicam:celeba_26k:Unet4M+U5+Unet4M_wave",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_aux1",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips_rotate10",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_ft_flips",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_ft_flips_rotate10",
]

# # -- to only use output from unrolled
# hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_aux1:
# skip_post: True
# skip_pre: True

save_idx: [1, 2, 4, 5, 9, 24, 33, 61]
n_iter_range: [100] # for ADMM

# simulating PSF
simulation:
use_waveprop: True
deadspace: True
scene2mask: 0.3
mask2sensor: 0.002
58 changes: 58 additions & 0 deletions configs/benchmark_digicam_mirflickr_single.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# python scripts/eval/benchmark_recon.py -cn benchmark_digicam_mirflickr_single
defaults:
- benchmark
- _self_

dataset: HFDataset
batchsize: 4
device: "cuda:0"

huggingface:
repo: "bezzam/DigiCam-Mirflickr-SingleMask-25K"
cache_dir: /dev/shm
psf: null # null for simulating PSF
image_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
flipud: False
flip_lensed: False # if rotate or flipud is True, apply to lensed
alignment:
top_left: [80, 100] # height, width
height: 200
downsample: 1


algorithms: [
"ADMM",

# -- reconstructions trained on measured data
"hf:digicam:mirflickr_single_25k:U5+Unet8M_wave",
"hf:digicam:mirflickr_single_25k:TrainInv+Unet8M_wave",
"hf:digicam:mirflickr_single_25k:MMCN4M+Unet4M_wave",
"hf:digicam:mirflickr_single_25k:MWDN8M_wave",
"hf:digicam:mirflickr_single_25k:Unet4M+TrainInv+Unet4M_wave",
"hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
"hf:digicam:mirflickr_single_25k:Unet2M+MMCN+Unet2M_wave",
"hf:digicam:mirflickr_single_25k:Unet2M+MWDN6M_wave",
"hf:digicam:mirflickr_single_25k:Unet4M+U10+Unet4M_wave",
"hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips",
"hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips_rotate10",

# ## -- reconstructions trained on other datasets/systems
# "hf:diffusercam:mirflickr:Unet4M+U10+Unet4M",
# "hf:tapecam:mirflickr:Unet4M+U10+Unet4M",
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
# "hf:digicam:celeba_26k:Unet4M+U5+Unet4M_wave",
# "hf:tapecam:mirflickr:Unet4M+U5+Unet4M",
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M",
# "hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave",
]

save_idx: [1, 2, 4, 5, 9]
n_iter_range: [100] # for ADMM

# simulating PSF
simulation:
use_waveprop: True
deadspace: True
scene2mask: 0.3
mask2sensor: 0.002
Loading
Loading