Code Monkey home page Code Monkey logo

pytorch-in-theano's Introduction

Pytorch inside Theano

(and pytorch wrapper for AIS)

This repo shows a dirty hack, how to run Pytorch graphs inside any Theano graph. Moreover, both forward and backward passes are supported. So whenever you want to mix Pytorch and Theano you may use the wrapper from this repo.

In particular, I wanted to use this code to evaluate a generative model using [1]. Their code is written in Theano and my AGE model was trained using Pytorch.

[1] On the Quantitative Analysis of Decoder-Based Generative Models, Yuhuai Wu, Yuri Burda, Ruslan Salakhutdinov, Roger Grosse, ICLR 2016

General usage

As easy as it could be.

from ops import pytorch_wrapper
f_theano = pytorch_wrapper(f_pytorch, dtype=dtype, debug=True)

And then use f_theano in your theano graphs. See simple_example.ipynb.

As AIS wrapper on MNIST dataset

  1. Train your pytoch model on MNIST dataset.

  2. Clone this repo with --recursive flag:

git clone --recursive https://github.com/DmitryUlyanov/pytorch_in_theano
  1. See AIS.ipynb for an example how I used it for AGE model on MNIST dataset. You will need to replace NetWrapper(net) in generator(z) with your network.

If you want to compare your generative model, here are the two likelihood scores I've computed for MNIST with z_dim=10:

method score
AGE 746
ALI 721

And the results from the paper: 705 for VAE and 328 for GAN.

On other datasets

To be true, I now do not remember why I had to modify sampler in eval_gen code. But probably it is because of shapes mismatch errors, that I struggled to figure out for a long time. So, please, before blindly running the code examine sampler file. For sure you need to put here the right value and probably change something in several other places.

Misc

Tested with python 2, theano=0.8.2.dev-901275534cbfe3fbbe290ce85d1abf8bb9a5b203, pytorch=0.2.0_4.

If you find this code helpful for your research, please cite this repo:

@misc{Ulyanov2017_ais_wrapper,
  author = {Ulyanov, Dmitry},
  title = {Pytorch wrapper for AIS},
  year = {2017},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/DmitryUlyanov/pytorch-in-theano}},
}

pytorch-in-theano's People

Contributors

dmitryulyanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

benjamesbabala

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.