导入需要用到的包
import tensorflow as tf
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
将 TensorFlow 日志信息输出
tf.logging.set_verbosity(tf.logging.INFO)
通过tf.layers来定义模型结果。这里可以使用原生态的TensorFlowAPI或者任何TensorFlow的高层封装。X给出了输入层张量,is_training指明了是否为训练。该函数返回前向传播的结果
def lenet(x, is_training):
#将输入转化为卷积层需要的形状
x = tf.reshape(x, shape=[-1, 28, 28, 1])
net = tf.layers.conv2d(x, 32, 5, activation=tf.nn.relu)
net = tf.layers.max_pooling2d(net, 2, 2)
net = tf.layers.conv2d(net,