根据莫烦学习视频教程~
这里使用了six layer
- 卷积层1:[28,28,1] 变为[28,28,32]
- 池化层1:[28,28,32] 变为[14,14,32]
- 卷积层2:[14,14,32] 变为[14,14,64]
- 池化层2:[14,14,64] 变为[7,7,64]
- 全连接层1:7764变为1024
- 全连接层2:1024变为10
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
import os
# number 1 to 10 data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
def compute_accuracy(v_xs, v_ys):
global prediction
y_pre = sess.run(prediction, feed_dict={xs: v_xs, keep_prob: 1})
correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
result = sess.run(accuracy, feed_dict={xs: v_xs, ys: v_ys, keep_prob: 1})
return result
def weight_variable(shape):
initial = tf.truncat