• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is the open source repository for our IEEE Transactions on Computational Imaging 2022 paper "dO: A differentiable engine for Deep Lens design of computational imaging systems".

dO: A differentiable engine for Deep Lens design of computational imaging systems

This is the PyTorch implementation for our paper "dO: A differentiable engine for Deep Lens design of computational imaging systems".

dO: A differentiable engine for Deep Lens design of computational imaging systems
Congli Wang, Ni Chen, and Wolfgang Heidrich
King Abdullah University of Science and Technology (KAUST)
IEEE Transactions on Computational Imaging 2022

Figure: Our engine dO models ray tracing in a lens system in a derivative-aware way, this enables ray tracing with back-propagation. To be derivative-aware, all modules must be differentiable so that gradients can be back-propagated from the error metric ϵ(p(θ)) to variable parameters θ. This is achieved by two stages of the reverse-mode AD: the forward and the backward passes. To ensure differentiability and efficiency, a custom ray-surface intersection solver is introduced. Instead of unrolling iterations for forward/backward, only the forward (no AD) is computed to obtain solutions at surfaces fi = 0, and gradients are amended afterwards.

TL; DR

We implemented in PyTorch a memory- and computation-efficient differentiable ray tracing system for optical designs, for design applications in freeform, Deep Lens, metrology, and more.

Update list

Target irradiance Optimized irradiance Optimized phase map
I_target I_final phase
Model (initial) Measurement Model (optimized)
I0 I optimized
  • nikon.py: Example on optimizing a Nikon design.
  • render_image.py: Example on rendering a single image from a design.
I_rendered
  • render_psf.py: Example on rendering PSFs of varying fields and depths for a design.
I_psf_z=-3000.0 I_psf_z=-2000.0
I_psf_z=-1500.0 I_psf_z=-1000.0
  • sanity_check.py: Example on Zemax versus dO for sanity check.

    dO Zemax
    sanity_check_dO sanity_check_zemax
  • spherical_aberration.py: Example on optimizing spherical aberration.

  • end2end_edof_backward_tracing.py: Example on end-to-end learning of wavefront coding, for extended depth of field applications, using backward ray tracing.

    iter_1_z=6000.0mm_images
  • Code cleanups and add comments.

  • File I/O with Zemax.

  • Mini GUI for easy operations.

Installation

Prerequisite

Though no GPUs are required, for speed's sake it is better to run the engine on a GPU.

Install the required Python packages:

pip install -r requirements.txt

Running examples

Examples are in the ./examples folder, and running some of the examples may require installing additional Python packages. Just follow the terminal hints, for example install the following:

pip install imageio opencv-python scikit-image

In case Python cannot find the path to dO, run the example scripts in the ./examples directory, for example:

cd <directory_of_this_repository>/examples
python3 misalignment_point.py

Summary

Target problem

  • General optical design/metrology or Deep Lens designs are parameter-optimization problems, and learning-based methods (e.g. with back-propagation) can be employed as solvers. This requires the optical modeling to be numerically derivative-aware (i.e. differentiable).
  • However, straightforward differentiable ray tracing with auto-diff (AD) is not memory/computation-efficient.

Our solutions

  • Differentiable ray-surface intersections requires a differentiable root-finding solver, which is typically iterative, like Newton's solver. Straightforward implementation is inefficient in both memory and computation. However, our paper makes an observation that, the status of the solver's iterations is irrelevant to the final solution -- That means, a differentiable root-finding solver can be smartly implemented as: (1) Find the optimal solution without AD (e.g. in block with torch.no_grad() in PyTorch), and (2) Re-engage AD to the solution found. This leads to great reduce in memory consumption, scaling up the system differentiability to large number of parameters or rays.
Figure: Comparison between the straightforward and our proposed differentiable ray-surface intersection methods for freeform surface optimization. Our method reduces the required memory by about 6 times.
  • When optimizing a custom merit function for image-based applications appended with a neural network, e.g. in Deep Lens designs, the training (or, back-propagation) can be split into two parts:

    • (Front-end) Optical design parameter optimization (training).
    • (Back-end) Neural network post-processing training.

    This de-coupling resembles the checkpointing technology in deep learning, and hence reducing the memory-hunger issue when tracing many number of rays.

Figure: Adjoint back-propagation (Adjoint BP) and the corresponding comparison against back-propagation (BP). Our implementation enables the scale up to many millions of rays while the conventional cannot.

Applications

Figure: Using dO the differentiable ray tracing system, we show the feasibility of advanced optical designs.

Relevant Project

Towards self-calibrated lens metrology by differentiable refractive deflectometry
Congli Wang, Ni Chen, and Wolfgang Heidrich
King Abdullah University of Science and Technology (KAUST)
OSA Optics Express 2021

GitHub: https://github.com/vccimaging/DiffDeflectometry.

Citation

@article{wang2022dO,
  title={{dO: A differentiable engine for Deep Lens design of computational imaging systems}},
  author={Wang, Congli and Chen, Ni and Heidrich, Wolfgang},
  journal={IEEE Transactions on Computational Imaging},
  year={2022},
  volume={8},
  number={},
  pages={905-916},
  doi={10.1109/TCI.2022.3212837},
  publisher={IEEE}
}

Contact

Please either open an issue, or contact Congli Wang [email protected] for questions.

More Repositories

1

MegapixelAO

This is the open source repository for our SIGGRAPH 2018 paper "Megapixel Adaptive Optics: Towards Correcting Large-scale Distortions in Computational Cameras".
C
37
star
2

Reconstrution_Through_Moving_Water

Source code for 2021 ICCV paper "In-the-Wild Single Camera 3D Reconstruction Through Moving Water Surfaces"
Python
35
star
3

CCSC_code_ICCV2017

This is the source code repository for the ICCV 2017 paper "Consensus Convolutional Sparse Coding".
MATLAB
25
star
4

DiffDeflectometry

This is the open source repository for our Optics Express 2021 paper "Towards self-calibrated lens metrology by differentiable refractive deflectometry".
Python
24
star
5

Deep-Red-Flash

Source code for 2021 CVPR paper "Seeing in Extra Darkness Using a Deep-red Flash"
Python
17
star
6

OCTDenoising

MATLAB
10
star
7

PhaseIntensityMicroscope

This is the open source repository for our Scientific Reports paper "Quantitative Phase and Intensity microscopy Using Snapshot White Light Wavefront Sensing".
C
10
star
8

Stochastic-Convolutional-Sparse-Coding

MATLAB
7
star
9

StereoEventPTV

Source Code for the Event PTV
MATLAB
6
star
10

IntraTomo

source code and data for ICCV2021 paper: IntraTomo: Self-supervised Learning-based Tomographyvia Sinogram Synthesis and Prediction
5
star
11

RainbowPIV

This is the source code for 2017 SIGGRAPH paper "Rainbow Particle Imaging Velocimetry for Dense 3D Fluid Velocity Imaging"
MATLAB
4
star
12

MetaISP

MetaISP – Exploiting Global Scene Structure for Accurate Multi-Device Color Rendition
Python
4
star
13

HexDOE

Source code for hexagonal wave propagation and phase retrieval for hexagonal DOE design
Jupyter Notebook
2
star