from fdl_examples.datatools import input_data mnist = input_data.read_data_sets("../../data/", one_hot=True) import tensorflow as tf import numpy as np from fdl_examples.chapter3.multilayer_perceptron_updated import inference, loss import matplotlib.pyplot as plt sess = tf.Session() x = tf.placeholder("float", [None, 784]) # mnist data image of shape 28*28=784 y = tf.placeholder("float", [None, 10]) # 0-9 digits recognition => 10 classes saver = tf.train.import_meta_graph('frozen_mlp_checkpoint/model-checkpoint-547800.meta') saver.restore(sess, 'frozen_mlp_checkpoint/model-checkpoint-547800') var_list_opt = [None, None, None, None, None, None] name_2_index = { "mlp_model/hidden_1/W:0" : 0, "mlp_model/hidden_1/b:0" : 1, "mlp_model/hidden_2/W:0" : 2, "mlp_model/hidden_2/b:0" : 3, "mlp_model/output/W:0" : 4, "mlp_model/output/b:0" : 5 } for x in tf.trainable_variables(): if x.name in name_2_index: index = name_2_index[x.name]
Project 2 - Network A - "Normal" MNIST data (ie not rotated or scaled) """ import sys sys.path.append('../../') sys.path.append('../') import numpy as np import tensorflow as tf import time, shutil, os from fdl_examples.datatools import input_data import matplotlib.pyplot as plt # read in MNIST data -------------------------------------------------- mnist = input_data.read_data_sets("../../data/", one_hot=True) # run network ---------------------------------------------------------- # Parameters learning_rate = 0.01 training_epochs = 5 # NOTE: you'll want to eventually change this batch_size = 100 display_step = 1 def inference(x, W, b): output = tf.nn.softmax(tf.matmul(x, W) + b) w_hist = tf.summary.histogram("weights", W) b_hist = tf.summary.histogram("biases", b)
plt.show() if __name__ == '__main__': parser = argparse.ArgumentParser( description='Test various optimization strategies') parser.add_argument('n_code', type=int) args = parser.parse_args() n_code = args.n_code log_dir = "mnist_autoencoder_hidden={}_logs/".format(n_code) ckpt = tf.train.get_checkpoint_state(log_dir) savepath = ckpt.model_checkpoint_path print("Use savepath: {}".format(savepath)) print("\nPULLING UP MNIST DATA") mnist = input_data.read_data_sets("data/", one_hot=False) print(mnist.test.labels) # Apply PCA print("\nSTARTING PCA") pca = decomposition.PCA(n_components=n_code) pca.fit(mnist.train.images) print("\nGENERATING PCA CODES AND RECONSTRUCTION") pca_codes = pca.transform(mnist.test.images) with tf.Graph().as_default(): with tf.variable_scope("autoencoder_model"): x = tf.placeholder("float", [None, 784]) phase_train = tf.placeholder(tf.bool) code = ae.encoder(x, n_code, phase_train) output = ae.decoder(code, n_code, phase_train)