Giter Club home page Giter Club logo

opticalcnn's Introduction

opticalCNN

Note 1: If you have a more up-to-date version of scipy, you may need to change the scipy.misc.imsave function to imageio.imwrite. Note 2: The Tensorflow fft2 function may also have changed in more recent updates, which has caused some differences in optimization results.

Our code was run with Python 3.5.5 and Tensorflow 1.4.0.

Example to optimize a single-layer optical correlator for QuickDraw-16:

  1. Download quickdraw-16 training dataset (see below) into assets folder
  2. onn_quickdraw-16-tiled.py: optimizes a single-layer tiled kernel PSF model for the quickdraw-16 dataset
  3. Walk through ONNMaskOpt.ipynb until the "Visualization of phase mask optimization" section. You can use the saved checkpoint folder we link below, or the checkpoint from running onn_quickdraw-16-tiled.py
  4. onn_maskopt.py: optimizes a phase mask to correspond to a pre-computed PSF. You can use the sample psf in the assets folder or use the one you save from the ONNMaskOpt.ipynb walkthrough
  5. Walk through ONNMaskOpt.ipynb from "Visualization of phase mask optimization" and plug in the checkpoint from onn_maskopt.py.

Example to optimize a hybrid two-layer CNN for CIFAR-10 (rough outline):

  1. Download the CIFAR-10 dataset.
  2. Train a network with hybrid_cifar10.py. There is much more code than necessary in this file from our experimenting. For similar conditions as in paper results, use: params['doTiledConv'] = False, params['doOpticalConv'] = False, params['doAmplitudeMask'] = False, params['doZernike'] = False, params['doFC'] = True, params['isNonNeg'] = True, params['doOptNeg'] = True, params['doNonnegReg'] = False
  3. Walk through the first sections of HybridNNMaskOpt.ipynb until "Extract optimized phase mask", making sure to save the tiled psf .npy file and training images for phase mask optimization. You'll need to change directories to suit your own needs.
  4. Optimize the phase mask for the weights of the learned convolutional kernels with hybrid_maskopt.py. Note that you can also run with the hybrid_maskopt.py phase mask optimization with the included file "assets/psf_hybrid_optneg_8x9_1e-1.npy"
  5. Fine tune the fully-connected layer with the learned phase mask (code not available).

Other code:

  • jupyter notebooks are useful for visualization, but in the current state they rely on files that may not be added yet
  • other scripts are added, but they are not completely demo-ready
  • the core code for hybrid two-layer networks have "hybrid" in the filename

Downloads:

Additional code used to interface with prototype hardware is available upon request.

Paper

Title: Hybrid optical-electronic convolutional neural networks with optimized diffractive optics for image classification

Authors: Julie Chang*, Vincent Sitzmann, Xiong Dun, Wolfgang Heidrich, and Gordon Wetzstein*

*Correspondence to: [email protected], [email protected]

Link to our paper: https://www.nature.com/articles/s41598-018-30619-y

Website

Link to our project page: http://www.computationalimaging.org/publications/hybrid-optical-electronic-convolutional-neural-networks/

Data

The original images used in all experiments were downloaded directly from MNIST, CIFAR-10, or Google QuickDraw source websites. The If you are interested in the CIFAR-10 dataset captured by our prototype, please send us an email.

opticalcnn's People

Contributors

juliechchang avatar vsitzmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.