Skip to content

Commit 28b73dd

Browse files
committed
threshhold adde, prints out solved board
1 parent cbaf5e1 commit 28b73dd

8 files changed

+144
-214
lines changed

CNN_MNIST.py

+14-47
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@
1111
# Import MNIST data
1212
from tensorflow.examples.tutorials.mnist import input_data
1313
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
14-
1514
dir = os.path.dirname(os.path.realpath(__file__))
1615

17-
# Parameters
16+
# Parameters for training
1817
learning_rate = 0.001
1918
training_iters = 50000
2019
batch_size = 128
21-
display_step = 10
2220

2321
# Network Parameters
2422
n_input = 784 # MNIST data input (img shape: 28*28)
2523
n_classes = 10 # MNIST total classes (0-9 digits)
2624
dropout = 0.75 # Dropout, probability to keep units
2725

28-
# tf Graph input
2926
x = tf.placeholder(tf.float32, [None, n_input])
3027
y = tf.placeholder(tf.float32, [None, n_classes])
3128
keep_prob = tf.placeholder(tf.float32) #dropout (keep probability)
3229

30+
31+
#Test method
32+
def show_image(self, img):
33+
cv2.imshow('img', img)
34+
cv2.waitKey(0)
35+
36+
#Needed for loading weights from disk
3337
def load_weights():
3438
with tf.Session() as sess:
3539
saver = tf.train.import_meta_graph(dir + '/vars.ckpt.meta')
@@ -45,70 +49,37 @@ def load_weights():
4549
b_out = graph.get_tensor_by_name('b_out:0').eval()
4650
return [wc1, wc2, wd1, w_out, bc1, bc2, bd1, b_out]
4751

48-
# Create some wrappers for simplicity
52+
53+
#Convolution + biad add + ReLU activation
4954
def conv2d(x, W, b, strides=1):
50-
# Conv2D wrapper, with bias and relu activation
5155
x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME')
5256
x = tf.nn.bias_add(x, b)
5357
return tf.nn.relu(x)
5458

55-
59+
#Maxpooling
5660
def maxpool2d(x, k=2):
5761
# MaxPool2D wrapper
5862
return tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1],
5963
padding='SAME')
6064

6165

62-
# Create model
66+
#Entire convolution net
6367
def conv_net(x, weights, biases, dropout):
6468
# Reshape input picture
6569
x = tf.reshape(x, shape=[-1, 28, 28, 1])
6670

67-
# Convolution Layer
6871
conv1 = conv2d(x, weights['wc1'], biases['bc1'])
69-
# Max Pooling (down-sampling)
7072
conv1 = maxpool2d(conv1, k=2)
7173

72-
# Convolution Layer
7374
conv2 = conv2d(conv1, weights['wc2'], biases['bc2'])
74-
# Max Pooling (down-sampling)
7575
conv2 = maxpool2d(conv2, k=2)
7676

77-
# Fully connected layer
78-
# Reshape conv2 output to fit fully connected layer input
77+
# Fully connected layer section
7978
fc1 = tf.reshape(conv2, [-1, weights['wd1'].get_shape().as_list()[0]])
8079
fc1 = tf.add(tf.matmul(fc1, weights['wd1']), biases['bd1'])
8180
fc1 = tf.nn.relu(fc1)
82-
# Apply Dropout
83-
fc1 = tf.nn.dropout(fc1, dropout)
84-
85-
# Output, class prediction
86-
out = tf.add(tf.matmul(fc1, weights['out']), biases['out'])
87-
return out
88-
89-
def conv_net2(x, weights, biases, dropout):
90-
# Reshape input picture
91-
x = tf.reshape(x, shape=[-1, 28, 28, 1])
92-
93-
# Convolution Layer
94-
conv1 = conv2d(x, weights['wc1'], biases['bc1'])
95-
# Max Pooling (down-sampling)
96-
conv1 = maxpool2d(conv1, k=2)
97-
98-
# Convolution Layer
99-
conv2 = conv2d(conv1, weights['wc2'], biases['bc2'])
100-
# Max Pooling (down-sampling)
101-
conv2 = maxpool2d(conv2, k=2)
102-
103-
# Fully connected layer
104-
# Reshape conv2 output to fit fully connected layer input
105-
fc1 = tf.reshape(conv2, [-1, weights['wd1'].shape[0]])
106-
fc1 = tf.add(tf.matmul(fc1, weights['wd1']), biases['bd1'])
107-
fc1 = tf.nn.relu(fc1)
108-
# Apply Dropout
10981
fc1 = tf.nn.dropout(fc1, dropout)
11082

111-
# Output, class prediction
11283
out = tf.add(tf.matmul(fc1, weights['out']), biases['out'])
11384
return out
11485

@@ -155,7 +126,7 @@ def conv_net2(x, weights, biases, dropout):
155126
# Run optimization op (backprop)
156127
sess.run(optimizer, feed_dict={x: batch_x, y: batch_y,
157128
keep_prob: dropout})
158-
if step % display_step == 0:
129+
if step % 10 == 0:
159130
# Calculate batch loss and accuracy
160131
loss, acc = sess.run([cost, accuracy], feed_dict={x: batch_x,
161132
y: batch_y,
@@ -179,10 +150,6 @@ def conv_net2(x, weights, biases, dropout):
179150

180151
batch_x = mnist.test.images[:10]
181152
batch_y = mnist.test.labels[:10]
182-
# print(batch_x[0])
183-
# img = np.reshape(batch_x[0], (28,28))
184-
# cv2.imshow('img', img)
185-
# cv2.waitKey(0)
186153

187154
out = sess.run(conv_net(batch_x, weights, biases, 1.0))
188155
for i in range(0, len(batch_y)):

Layout.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from square import *
1+
from Square import *
22

33
class Layout(object):
44
def __init__(self, length):
@@ -44,4 +44,4 @@ def __init__(self,length):
4444
class Row(Layout):
4545

4646
def __init__(self,length):
47-
super(Row,self).__init__(length)
47+
super(Row,self).__init__(length)

NumberClassification.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def classify_images(self, images):
3333
print(images.shape)
3434
images = tf.cast(images, tf.float32)
3535
with tf.Session() as sess:
36-
return sess.run(self.conv_net(images))
36+
pred = sess.run(self.conv_net(images))
37+
print(len(pred))
38+
return pred
3739

3840
# #batch_size = 10
3941
# #images = tf.cast(images, tf.float32)
@@ -44,8 +46,6 @@ def classify_images(self, images):
4446
# with tf.Session() as sess:
4547
# return sess.run(self.conv_net(batch_x)), batch_y
4648

47-
48-
4949
def maxpool2d(self, x, k=2):
5050
return tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME')
5151

@@ -56,25 +56,19 @@ def conv2d(self, x, W, b, strides=1):
5656

5757
def conv_net(self, x):
5858
# Reshape input picture
59-
x = tf.reshape(x, shape=[-1, 28, 28, 1])
59+
x = tf.reshape(x, shape=[-1, 28, 28, 1])
6060

61-
# Convolution Layer
6261
conv1 = self.conv2d(x, self.weights['wc1'], self.biases['bc1'])
63-
# Max Pooling (down-sampling)
6462
conv1 = self.maxpool2d(conv1, k=2)
6563

66-
# Convolution Layer
6764
conv2 = self.conv2d(conv1, self.weights['wc2'], self.biases['bc2'])
68-
# Max Pooling (down-sampling)
6965
conv2 = self.maxpool2d(conv2, k=2)
7066

7167
# Fully connected layer
72-
# Reshape conv2 output to fit fully connected layer input
7368
fc1 = tf.reshape(conv2, [-1, self.weights['wd1'].shape[0]])
7469
fc1 = tf.add(tf.matmul(fc1, self.weights['wd1']), self.biases['bd1'])
7570
fc1 = tf.nn.relu(fc1)
7671

77-
# Output, class prediction
7872
out = tf.add(tf.matmul(fc1, self.weights['out']), self.biases['out'])
7973
return out
8074

0 commit comments

Comments
 (0)