1998年Y.LeCun等提出的GradientBased Learning Applied to Document Recognitionhttps://ieeexplore.ieee.org/document/726791
今天学习针对28*28*1的手写数字进行复现lenet网络。比0.9808高呀。lenet是CNN的鼻祖呀 卷积神经网络。
这个函数img.resize((width, height),Image.ANTIALIAS)
第二个参数:
Image.NEAREST :低质量
Image.BILINEAR:双线性
Image.BICUBIC :三次样条插值
Image.ANTIALIAS:高质量
#coding:utf-8
import tensorflow as tf
#每张图片分辨率为28*28
IMAGE_SIZE = 28
#Mnist数据集为灰度图,故输入图片通道数NUM_CHANNELS取值为1
NUM_CHANNELS = 1
#第一层卷积核大小为5
CONV1_SIZE = 5
#卷积核个数为32
CONV1_KERNEL_NUM = 32
#第二层卷积核大小为5
CONV2_SIZE = 5
#卷积核个数为64
CONV2_KERNEL_NUM = 64
#全连接层第一层为 512 个神经元
FC_SIZE = 512
#全连接层第二层为 10 个神经元
OUTPUT_NODE = 10
#权重w计算
def get_weight(shape, regularizer):
w = tf.Variable(tf.truncated_normal(shape,stddev=0.1))
if regularizer != None: tf.add_to_collection('losses', tf.contrib.layers.l2_regularizer(regularizer)(w))
return w
#偏置b计算
def get_bias(shape):
b = tf.Variable(tf.zeros(shape))
return b
#卷积层计算
def conv2d(x,w):
return tf.nn.conv2d(x, w