-
-
Save tigerneil/341a39759a9fedc2017b499f7ae2c1ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loss=tf.reduce_mean(-elbo) | |
lr=tf.constant(0.001) | |
train_op=tf.train.AdamOptimizer(learning_rate=lr).minimize(loss,var_list=slim.get_model_variables()) | |
init_op=tf.initialize_all_variables() | |
# get data | |
data = input_data.read_data_sets('/tmp/', one_hot=True).train | |
BATCH_SIZE=100 | |
NUM_ITERS=50000 | |
tau0=1.0 # initial temperature | |
np_temp=tau0 | |
np_lr=0.001 | |
ANNEAL_RATE=0.00003 | |
MIN_TEMP=0.5 | |
dat=[] | |
sess=tf.InteractiveSession() | |
sess.run(init_op) | |
for i in range(1,NUM_ITERS): | |
np_x,np_y=data.next_batch(BATCH_SIZE) | |
_,np_loss=sess.run([train_op,loss],{x:np_x,tau:np_temp,lr:np_lr}) | |
if i % 100 == 1: | |
dat.append([i,np_temp,np_loss]) | |
if i % 1000 == 1: | |
np_temp=np.maximum(tau0*np.exp(-ANNEAL_RATE*i),MIN_TEMP) | |
np_lr*=0.9 | |
if i % 5000 == 1: | |
print('Step %d, ELBO: %0.3f' % (i,-np_loss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment