Giter VIP home page Giter VIP logo

diffractive-deep-neural-network's Introduction

Diffractive Deep Neural Network (D${}^2$NN)

Get Started

OpticalLayer.py includes two types of Layers. Diffraction is the free space propagtion layer and DiffLayer provides phase modulation.

from torch import nn
from OpticalLayers import DiffLayer,  Diffraction

Build your own model like you do in PyTorch. See model.py for details.

class Onn(nn.Module):
    def __init__(self, M, L, lambda0, z):
        super(Onn, self).__init__()

        # free space propagation
        self.layer0 = Diffraction(M, L, lambda0, z[0]) 

        # phase modulation
        self.DiffLayer1 = DiffLayer(M, L, lambda0, z[1])
        self.DiffLayer2 = DiffLayer(M, L, lambda0, z[2])
        self.DiffLayer3 = DiffLayer(M, L, lambda0, z[3])

    def forward(self, u):        
        u = self.layer0(u)
        u = self.DiffLayer1(u)
        u = self.DiffLayer2(u)
        u = self.DiffLayer3(u)
        return u
######################## Optical parameters /mm ##########################
c = 3e8*1e3             # speed of light
f = 400e9               # 400GHz
lambda0 = c/f           # wavelength
L = 80                  # DOE size

device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
M = 256                 # sample numbers
z = [30,30,30,30]    
onn = Onn(M, L, lambda0, z).to(device)

Prepare your own train data and use the following line to train the model. The return values are Optical Neural Networks(onn), train/valitation loss/accuracy, validation resuls(I_val) and validation labels(labels_val).

onn, train_losses, train_accies, val_losses, val_accies, I_val, labels_val =\
        train(onn,criterion, optimizer,
                train_loader,val_loader, 
                model_save_path, epoch_num)    

Result

Run onn_train.py. A three-layer D$^2$NN for MNIST data classification was trained. The results are shown as follow. The accuracy is about 90%.

Reference

  • Lin, Xing, et al. "All-optical machine learning using diffractive deep neural networks." Science 361.6406 (2018): 1004-1008.

diffractive-deep-neural-network's People

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.