<jupyter_start><jupyter_text>training the network<jupyter_code>init=tf.global_variables_initializer()
train_mse_save=[]
test_mse_save=[]
mse_lr=0.1
training_loss=0.1
with tf.Session() as sess:
    init.run()
    try:
        saver.restore(sess, checkpoints_savepath)
    except:
        print("restoring error, will start over!")
    for epoch in range(1,n_epochs+1):
        X_train=shuffle(X_train)
        for batch in range(n_batches):
            X_batch=X_train[batch*batch_size:batch*batch_size+batch_size,]
            training_loss=loss.eval(feed_dict={X:X_batch})*mse_lr+(1-mse_lr)*training_loss
            sess.run(training_op,feed_dict={X:X_batch})
        testing_loss=loss.eval(feed_dict={X:X_test})
        print("epoch {:3d} MSE(training_batch) {:7.6f} MSE(testing) {:7.6f}".\
              format(epoch,training_loss,testing_loss),end="\r")
        train_mse_save.append(training_loss)
        test_mse_save.append(testing_loss)
        if epoch % 10==0:
            save_path=saver.save(sess,checkpoints_savepath)<jupyter_output>INFO:tensorflow:Restoring parameters from model_checkpoints_large/CAE_05192018_2layers_xsmall.ckpt
restoring error, will start over!
epoch 200 MSE(training_batch) 0.002206 MSE(testing) 0.002187<jupyter_text>testing the output<jupyter_code>line_train,=plt.plot(train_mse_save,label="training")
line_test,=plt.plot(test_mse_save,label="testing")
plt.legend(handles=[line_train, line_test])<jupyter_output><empty_output><jupyter_text>visualize the reconstruction<jupyter_code>with tf.Session() as sess:
    init.run()
    saver.restore(sess, checkpoints_savepath)
    n_image_row=4
    n_image_col=2
    total_image=n_image_row*n_image_col
    image_index=random.sample(list(range(X_test.shape[0])),n_image_row)
    for i,k in enumerate(image_index):
        plt.subplot(n_image_row,n_image_col,i*n_image_col+1)
        plt.imshow(X_test[k])
        plt.subplot(n_image_row,n_image_col,i*n_image_col+2)
        reconstructed_image=reconstruction.eval(feed_dict={X:[X_test[k]]})
        plt.imshow(reconstructed_image[0])<jupyter_output>INFO:tensorflow:Restoring parameters from model_checkpoints_large/CAE_05192018_2layers_xsmall.ckpt<jupyter_text>visualize the output from the encoder<jupyter_code>with tf.Session() as sess:
    init.run()
    saver.restore(sess, checkpoints_savepath)
    n_image_row=5
    n_image_col=2
    total_image=n_image_row*n_image_col
    image_index=list(range(10))
    for i,k in enumerate(image_index):
        plt.subplot(n_image_row,n_image_col,i+1)
        encoded_image=Z1.eval(feed_dict={X:[X_test[0]]})
        plt.imshow(encoded_image[0,:,:,k],cmap="gray")
with tf.Session() as sess:
    init.run()
    saver.restore(sess, checkpoints_savepath)
    n_image_row=2
    n_image_col=2
    total_image=n_image_row*n_image_col
    image_index=list(range(3))
    for i,k in enumerate(image_index):
        plt.subplot(n_image_row,n_image_col,i+1)
        encoded_image=Z2.eval(feed_dict={X:[X_test[200]]})
        plt.imshow(encoded_image[0,:,:,k],cmap="gray")
with tf.Session() as sess:
    init.run()
    saver.restore(sess, checkpoints_savepath)
    n_image_row=2
    n_image_col=2
    total_image=n_image_row*n_image_col
    encoded_image=Z2.eval(feed_dict={X:[X_test[200]]})
    plt.imshow(encoded_image[0,:,:,:])<jupyter_output>INFO:tensorflow:Restoring parameters from model_checkpoints_large/CAE_05192018_2layers_xsmall.ckpt<jupyter_text>visualize the filters (first layer)<jupyter_code>image_index=[(a,b) for a in range(3) for b in range(10)]
with tf.Session() as sess:
    init.run()
    saver.restore(sess, checkpoints_savepath)
    n_image_row=4
    n_image_col=8
    total_image=n_image_row*n_image_col
    
    for i,t in enumerate(image_index):
        a,b=t
        plt.subplot(n_image_row,n_image_col,i+1)
        filter1=W1.eval()
        plt.imshow(filter1[:,:,a,b],cmap="gray")
        plt.axis('off')<jupyter_output>INFO:tensorflow:Restoring parameters from model_checkpoints_large/CAE_05192018_2layers_xsmall.ckpt
{'fraction_non_alphanumeric': 0.1219147344801795, 'fraction_numerical': 0.026676639242084268, 'mean_word_length': 5.042168674698795, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '305333', 'license': 'MIT', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1550, 'n_words': 179, 'path': 'flappy_cnn_autoencoder_decoder_2_layers.ipynb', 'repo_name': 'wayneyeye/flappybird_AI', 'size': '4011'}