Giter VIP home page Giter VIP logo

tf-dann's Introduction

Domain-Adversarial Training of Neural Networks in Tensorflow

"Unsupervised Domain Adaptation by Backpropagation" introduced a simple and effective method for accomplishing domain adaptation with SGD with a gradient reversal layer. This work was elaborated and extended in "Domain-Adversarial Training of Neural Networks". For more information as well as a link to an equivalent implementation in Caffe, see http://sites.skoltech.ru/compvision/projects/grl/.

The Blobs-DANN.ipynb shows some basic experiments on a very simple dataset. The MNIST-DANN.ipynb recreates the MNIST experiment from the papers on a synthetic dataset. Instructions to generate the synthetic dataset are below. To run any of the experiment code, you will need to build the gradient reversal layer.

Gradient Reversal Layer

The flip_gradient operation is implemented in Python by using tf.gradient_override_map to override the gradient of tf.identity. Refer to flip_gradient.py to see how this is implemented.

from flip_gradient import flip_gradient

# Flip the gradient of y w.r.t. x and scale by l (defaults to 1.0)
y = flip_gradient(x, l)

MNIST Experiments

The MNIST-DANN.ipynb notebook implements the MNIST experiments for the paper with the same model and optimization parameters, including the learning rate and adaptation parameter schedules. Rough results are below (more training would likely improve results - # epochs are not reported in the paper).

Method Target acc (paper) Target acc (this repo w/ 10 epochs)
Source Only 0.5225 0.4801
DANN 0.7666 0.7189

Build MNIST-M dataset

The MNIST-M dataset consists of MNIST digits blended with random color patches from the BSDS500 dataset. To generate a MNIST-M dataset, first download the BSDS500 dataset and run the create_mnistm.py script:

curl -O http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/BSR/BSR_bsds500.tgz
python create_mnistm.py

This may take a couple minutes and should result in a mnistm_data.pkl file containing generated images.

Contribution

It would be great to add other experiments to this repository. Feel free to make a PR if you decide to recreate other results from the papers or new experiments entirely.

tf-dann's People

Contributors

pumpikano avatar

Watchers

 avatar  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.