Last active
October 14, 2016 12:43
-
-
Save amkatrutsa/6510cfde0ab1cd5dae580fbca1c884b1 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
| tf.reset_default_graph() | |
| input_image = tf.placeholder(tf.float32, shape=[X_train_prep.shape[0], X_train_prep.shape[1]]) | |
| U = tf.Variable(tf.truncated_normal([X_train_prep.shape[0], hidden_dim], stddev=0.01), name="U") | |
| V = tf.Variable(tf.truncated_normal([hidden_dim, initial_dim], stddev=0.01), name="V") | |
| approximation_loss = tf.sqrt(tf.reduce_sum(tf.square(tf.sub(input_image, tf.matmul(U, V))))) | |
| # Define optimizer and other constants | |
| init = tf.initialize_all_variables() | |
| sess = tf.InteractiveSession() | |
| sess.run(init) | |
| for num in xrange(num_switches): | |
| if num % 2 == 0: | |
| print "Optimization by U", num | |
| grads_and_vars = optimizer.compute_gradients(approximation_loss, var_list=[V]) | |
| else: | |
| print "Optimization by V", num | |
| grads_and_vars = optimizer.compute_gradients(approximation_loss, var_list=[U]) | |
| operation = optimizer.apply_gradients(grads_and_vars) | |
| for iteration in xrange(num_epoch): | |
| sess.run(operation, feed_dict={input_image: X_train_prep}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment