In [1]:
%matplotlib inline
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
import prettytensor as pt
In [2]:
from tensorflow.examples.tutorials.mnist import input_data
dataset = input_data.read_data_sets("data/MNIST/", one_hot=True)
In [3]:
image_size = 28
image_shape = (image_size, image_size)
image_flat = image_size*image_size
num_class = 10
In [4]:
layer1_filter_size = 5
layer1_input_channel = 1
layer1_output_channel = 16
layer2_filter_size = 5
layer2_output_channel = 36
num_output_fc1 = 128
num_output_fc2 = 10
In [5]:
x = tf.placeholder(tf.float32, [None, image_flat])
In [6]:
y = tf.placeholder(tf.float32, [None, num_class])
In [7]:
y_true_class = tf.argmax(y, dimension=1)
In [8]:
x_image = tf.reshape(x, [-1, image_size, image_size, layer1_input_channel])
In [11]:
x_pretty = pt.wrap(x_image)
In [15]:
with pt.defaults_scope(activation_fn = tf.nn.relu):
y_pred, loss = x_pretty.\
conv2d(kernel = 5, depth = 16, name="layer_conv1").\
max_pool(kernel=2, stride=2)./
conv2d(kernel=5, depth = 36, name = "layer_conv2").\
max_pool(kernel=2, stride=2)./
flatten().\
fully_connected(size=128, name='layer_fc1').\
softmax_classifier(num_classes=num_classes, labels=y_true)
In [ ]: