Code Monkey home page Code Monkey logo

neuralode's Introduction

Neural ODEs and Adversarial Attacks

Code for my blog post on Neural ODEs and Adversarial Attacks in which I train neural ODEs on MNIST with different end times and compare their adversarial robustness. I also adversarially train a neural ODE and investigate how this affects its dynamics. It seems like adversarially trained ODEs map different classes of inputs to different equilibria or steady states of the ODE.

Overview of the code:

Modules

  • modules.py: Contains the pytorch modules used to build the model to be trained.
    • ConvODEfunc is the neural network which parameterizes the dynamics of the neural ODE ( f(z, t; theta) ).
    • ODEBlock wraps a general function like ConvODEfunc and calls the ODE solver.
    • ODEBlockRandTime same as above, but supports random end times.
    • ODEnetRandTime is the top level module used for MNIST classification. It has an initial convolution and downsampling layer before passing into the ODE-net, and a final fully connected layer to output class scores.
  • mnist_dataset.py A pytorch dataset to handle MNIST images and load them directly on GPU or CPU.
  • training_functions.py: Contains the train_on_batch and validate functions used in the training loop. Also has LR scheduling callbacks.
  • data_ingredient.py: Sacred ingredient which sets up data loaders.
  • model_ingredient.py: Sacred ingredient which instantiates the required ODEnet models using the config.
  • adversarial.py: Code for adversarial attacks. Includes FGSM and Projected Gradient Descent(PGD).

Scripts

These are sacred experiments. Use this general command to run them:

python <script_name>.py with <config_updates>

Run the following to see the config parameters:

python <script_name>.py print_config

  • train.py: Loads the model and data ingredients and uses the train_on_batch and validate functions to train the model. Also contains the code which creates the optimizer.
  • test.py: Run inference on trained models by specifying a run directory and epoch to load.
  • adv_train.py: Train a model with adversarial data augmentation.
  • adv_test.py: Test a model with adversarial attacks.
  • time_test.py: Test a neural ODE model over a range of end times.

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.