话不多说上代码 三层卷积+四个全连接+各种参数=0.996 acc
图片尺寸变化为:28x28x1 到 14x14x32 到 7x7x64 到 4x4x128 到 1024 到 512 到10
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data #避免导入出错
from numpy import outer
mnist = input_data.read_data_sets("MNIST/",one_hot=True)
learning_rate = 0.001
training_iters = 200000
batch_size = 128
display_step = 10
n_input = 784 #28 x 28
n_classes = 10
dropout = 0.9# 全连接多设置大一些
#tf Graph input
x = tf.placeholder(tf.float32,[None,n_input])
y = tf.placeholder(tf.float32,[None,n_classes])
keep_prob = tf.placeholder(tf.float32)#drop(keep probability)
def conv2d(image,w,b):
return tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(image,w,strides=[1,1,1,1],padding='SAME'),b))
def max_pooling(image,k):
return tf.nn.max_po