Giter Club home page Giter Club logo

bdl's Introduction

Natural-Gradient VI for Bayesian Neural Nets

Minimal code to run Variational Online Gauss-Newton(VOGN) algorithm on MNIST and CIFAR10 datasets using Convolutional Neural Networks. The optimizer is compatible with any PyTorch model containing fully connected or convolutional layers. Layers without trainable parameters such as pooling layers or batch normalization layers with affine = False can also be used.

Requirements

The project has following dependencies:

  • Python >= 3.5
  • PyTorch == 1.0

Scripts Explanation

There are 5 Python scripts:

  • main.py: This is the main script to perform training and visualize the results
  • vogn.py: This script contains the VOGN optimizer
  • datasets.py: This script downloads and create PyTorch data loaders for MNIST and CIFAR10. The default data folder is ./data/
  • models.py: This script contains PyTorch implementations of 3 Layer Convolutional Network and LeNet5. The details of model architectures are in Table 1 of attached note.
  • utils.py: This script contains the function to perform model training and return metric history on test and train datasets.

The simplest way to perform training is to run python main.py within a suitable anaconda environment.

How to use VOGN optimizer

VOGN is intended as a drop-in replacement for Adam optimizer. However, VOGN has two important distinctions from Adam. When the opitmizer is initialized, model.parameters() in Adam must be replaced with model. Within the training loop, forward pass and evaluating loss must be performed within a closure(). It is important to not perform loss.backward() as that is performed within opitimizer.step(). The following is an example of training loop for VOGN:

for data in dataloader:
    inputs, labels = data
    def closure():
        optimizer.zero_grad()
        logits = model(inputs)
        loss = criterion(logits, labels)
    loss = optimizer.step()

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.