Skip to content

Instantly share code, notes, and snippets.

@ericjang
Last active November 9, 2016 05:32
Show Gist options
  • Save ericjang/0ab1531dcd521390960635bff79a44b1 to your computer and use it in GitHub Desktop.
Save ericjang/0ab1531dcd521390960635bff79a44b1 to your computer and use it in GitHub Desktop.
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
slim=tf.contrib.slim
Bernoulli = tf.contrib.distributions.Bernoulli
K=10 # number of classes
N=30 # number of categorical distributions
# input image x (shape=(batch_size,784))
x = tf.placeholder(tf.float32,[None,784])
# variational posterior q(y|x), i.e. the encoder (shape=(batch_size,200))
net = slim.stack(x,slim.fully_connected,[512,256])
# unnormalized logits for N separate K-categorical distributions (shape=(batch_size*N,K))
logits_y = tf.reshape(slim.fully_connected(net,K*N,activation_fn=None),[-1,K])
q_y = tf.nn.softmax(logits_y)
log_q_y = tf.log(q_y+1e-20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment