Skip to content

Commit

Permalink
Merge with main.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Jul 28, 2023
2 parents 0f92ea6 + 096189d commit 0f7c51e
Show file tree
Hide file tree
Showing 37 changed files with 1,306 additions and 184 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ Added
- Authors at top of source code files.
- Add paramiko as dependency for remote capture and display.
- Mask module, for CodedAperture (FlatCam), PhaseContour (PhlatCam), and FresnelZoneAperture.
- Script for measuring arbitrary dataset (from Raspberry Pi).
- Support for preprocessing and postprocessing, such as denoising, in ``TrainableReconstructionAlgorithm``. Both trainable and fix postprocessing can be used.
- Utilities to load a trained DruNet model for use as postprocessing in ``TrainableReconstructionAlgorithm``.
- Support for unrolled loading and inference in the script ``admm.py``.


Changed
~~~~~~~

- Simpler remote capture and display scripts with Hydra.
- Group source code into four modules: ``hardware``, ``recon``, ``utils``, ``eval``.
- Split scripts into subfolders.


Bugfix
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ Building documentation
# build documentation
(lensless_docs) python setup.py build_sphinx
# or
(lensless_docs) (cd docs && make html)
To rebuild the documentation from scratch:

.. code:: bash
Expand Down
8 changes: 8 additions & 0 deletions configs/analyze_dataset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hydra:
job:
chdir: True # change to output folder

dataset_path: null
desired_range: [190, 254]
delete_saturated: True
n_files: null
3 changes: 2 additions & 1 deletion configs/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ hydra:
job:
chdir: True

device: "cuda"
# numbers of iterations to benchmark
n_iter_range: [5, 10, 30, 60, 100, 200, 300]
# number of files to benchmark
n_files: 200
#How much should the image be downsampled
downsample: 8
#algorithm to benchmark
algorithms: ["ADMM", "ADMM_Monakhova2019", "FISTA", "GradientDescent", "NesterovGradientDescent"]
algorithms: ["ADMM", "ADMM_Monakhova2019", "FISTA"] #["ADMM", "ADMM_Monakhova2019", "FISTA", "GradientDescent", "NesterovGradientDescent"]

# Hyperparameters
nesterov:
Expand Down
13 changes: 10 additions & 3 deletions configs/collect_dataset.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# python scripts/collect_dataset_on_device.py -cn collect_dataset

input_dir: data/celeba_mini
input_file_ext: jpg

Expand All @@ -16,6 +18,11 @@ start_delay: null # how much time (in minutes) to wait before starting
# measurement parameters
dummy: False # simply copy file to output folder for testing

# ideal image levels
max_level: 254
min_level: 200
max_tries: 6

# -- display parameters
display:
output_fp: "~/LenslessPiCam_display/test.png"
Expand All @@ -24,15 +31,15 @@ display:
pad: 0
hshift: 0
vshift: -10
brightness: 50
brightness: 80 # max brightness
rot90: 3

capture:
delay: 2 # to allow picture to display
config_pause: 2
iso: 100
res: null
down: 8
exposure: 0.02
down: 4
exposure: 0.02 # min exposure
awb_gains: [1.9, 1.2] # red, blue
# awb_gains: null
9 changes: 9 additions & 0 deletions configs/defaults_recon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ admm:
mu2: 1e-5
mu3: 4e-5
tau: 0.0001
#Loading unrolled model
unrolled: false
checkpoint_fp: null
pre_process_model:
network : null # UnetRes or DruNet or null
depth : 2 # depth of each up/downsampling layer. Ignore if network is DruNet
post_process_model:
network : null # UnetRes or DruNet or null
depth : 2 # depth of each up/downsampling layer. Ignore if network is DruNet

apgd:
# Stopping criteria
Expand Down
4 changes: 2 additions & 2 deletions configs/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# chdir: True # change to output folder


fp: data/original/thumbs_up.png
fp: data/original/tree.png
output: demo_lensless # output folder for results
save: True
plot: False
Expand Down Expand Up @@ -31,7 +31,7 @@ capture:
gamma: null # for visualization
exp: 0.02
delay: 2
script: ~/LenslessPiCam/scripts/on_device_capture.py
script: ~/LenslessPiCam/scripts/measure/on_device_capture.py
iso: 100
config_pause: 2
sensor_mode: "0"
Expand Down
1 change: 1 addition & 0 deletions configs/telegram_demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rpi_lensed_hostname: null
# psf: null
psf:
fp: data/psf/tape_rgb_31032023.png
# fp: data/psf/tape_rgb.png # wrong
downsample: 4

# which hydra config to use and available algos
Expand Down
21 changes: 15 additions & 6 deletions configs/unrolled_recon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ preprocess:
display:
# How many iterations to wait for intermediate plot.
# Set to negative value for no intermediate plots.
disp: 100
disp: 400
# Whether to plot results.
plot: True
# Gamma factor for plotting.
Expand All @@ -54,7 +54,12 @@ reconstruction:
mu2: 1e-4
mu3: 1e-4
tau: 2e-4

pre_process:
network : UnetRes # UnetRes or DruNet or null
depth : 2 # depth of each up/downsampling layer. Ignore if network is DruNet
post_process:
network : UnetRes # UnetRes or DruNet or null
depth : 2 # depth of each up/downsampling layer. Ignore if network is DruNet

# Train Dataset

Expand Down Expand Up @@ -90,13 +95,17 @@ simulation:
#Training

training:
batch_size: 16
epoch: 10
batch_size: 8
epoch: 50
#In case of instable training
skip_NAN: True
slow_start: False #float how much to reduce lr for first epoch


optimizer:
type: Adam
lr: 1e-4
lr: 1e-6

loss: 'l2'
# set lpips to false to deactivate. Otherwise, give the weigth for the loss (the main loss l2/l1 always having a weigth of 1)
lpips: 0.6
lpips: 1.0
14 changes: 7 additions & 7 deletions docs/source/measurement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can remotely capture data with the following script:

.. code:: bash
python scripts/remote_capture.py \
python scripts/measure/remote_capture.py \
rpi.username=USERNAME \
rpi.hostname=HOSTNAME \
plot=True
Expand All @@ -66,12 +66,12 @@ you can run the above script with a different configation:

.. code:: bash
python scripts/remote_capture.py -cn capture_bayer \
python scripts/measure/remote_capture.py -cn capture_bayer \
rpi.username=USERNAME \
rpi.hostname=HOSTNAME
You can then use ``scripts/analyze_image.py`` to play around with the red and
You can then use ``scripts/measure/analyze_image.py`` to play around with the red and
blue gains to find the best white balance for your camera.


Expand Down Expand Up @@ -108,7 +108,7 @@ image on the Raspberry Pi:

.. code-block:: bash
python scripts/remote_display.py \
python scripts/measure/remote_display.py \
rpi.username=USERNAME \
rpi.hostname=HOSTNAME \
fp=FP
Expand All @@ -134,7 +134,7 @@ Script that can be launched from the Raspberry Pi:

.. code:: bash
python scripts/collect_mnist_on_device.py --input_dir MNIST_original \
python scripts/measure/collect_mnist_on_device.py --input_dir MNIST_original \
--output_dir MNIST_meas
If the MNIST dataset is not available at ``MNIST_original`` it will be
Expand All @@ -151,7 +151,7 @@ copying files back and forth):

.. code:: bash
python scripts/collect_mnist.py --hostname <IP_ADDRESS> --output_dir MNIST_meas
python scripts/measure/collect_mnist.py --hostname <IP_ADDRESS> --output_dir MNIST_meas
Collecting arbitrary dataset
Expand All @@ -162,7 +162,7 @@ camera. The script can be launched **from the Raspberry Pi**:

.. code::
python scripts/collect_dataset_on_device.py
python scripts/measure/collect_dataset_on_device.py
By default this script will collect a subset (100 files) of the `CelebA <https://mmlab.ie.cuhk.edu.hk/projects/CelebA.html>`__
dataset.
Expand Down
9 changes: 7 additions & 2 deletions lensless/eval/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ def benchmark(model, dataset, batchsize=1, metrics=None, **kwargs):
metrics = {
"MSE": MSELoss().to(device),
"MAE": L1Loss().to(device),
"LPIPS": lpip.LearnedPerceptualImagePatchSimilarity(net_type="vgg").to(device),
"LPIPS_Vgg": lpip.LearnedPerceptualImagePatchSimilarity(
net_type="vgg", normalize=True
).to(device),
"LPIPS_Alex": lpip.LearnedPerceptualImagePatchSimilarity(
net_type="alex", normalize=True
).to(device),
"PSNR": psnr.PeakSignalNoiseRatio().to(device),
"SSIM": StructuralSimilarityIndexMeasure().to(device),
"ReconstructionError": None,
Expand All @@ -283,7 +288,7 @@ def benchmark(model, dataset, batchsize=1, metrics=None, **kwargs):
prediction = prediction.reshape(-1, *prediction.shape[-3:]).movedim(-1, -3)
lensed = lensed.reshape(-1, *lensed.shape[-3:]).movedim(-1, -3)
# normalization
prediction_max = torch.amax(prediction, dim=(1, 2, 3), keepdim=True)
prediction_max = torch.amax(prediction, dim=(-1, -2, -3), keepdim=True)
if torch.all(prediction_max != 0):
prediction = prediction / prediction_max
else:
Expand Down
2 changes: 1 addition & 1 deletion lensless/hardware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def display(

# assumes that `LenslessPiCam` is in home directory and environment inside `LenslessPiCam`
rpi_python = "~/LenslessPiCam/lensless_env/bin/python"
script = "~/LenslessPiCam/scripts/prep_display_image.py"
script = "~/LenslessPiCam/scripts/measure/prep_display_image.py"
remote_tmp_file = "~/tmp_display.png"
display_path = "~/LenslessPiCam_display/test.png"

Expand Down
Loading

0 comments on commit 0f7c51e

Please sign in to comment.