|
|
|
|
@ -37,7 +37,23 @@ import numpy as np
|
|
|
|
|
learning_rate = 0.001 #学习率
|
|
|
|
|
num_steps = 2000 # 训练步数
|
|
|
|
|
batch_size = 128 # 训练数据批的大小
|
|
|
|
|
# Network Parameters,网络参数
|
|
|
|
|
num_input = 784 # MNIST数据输入 (img shape: 28*28)
|
|
|
|
|
num_classes = 10 # MNIST所有类别 (0-9 digits)
|
|
|
|
|
dropout = 0.75 # Dropout, probability to keep units = (1-p),保留神经元相应的概率为(1-p)=(1-0.75)=0.25
|
|
|
|
|
|
|
|
|
|
# Create the neural network,创建深度神经网络
|
|
|
|
|
def conv_net(x_dict, n_classes, dropout, reuse, is_training):
|
|
|
|
|
|
|
|
|
|
# Define a scope for reusing the variables,确定命名空间
|
|
|
|
|
with tf.variable_scope('ConvNet', reuse=reuse):
|
|
|
|
|
# TF Estimator类型的输入为像素
|
|
|
|
|
x = x_dict['images']
|
|
|
|
|
|
|
|
|
|
# MNIST数据输入格式为一位向量,包含784个特征 (28*28像素)
|
|
|
|
|
# 用reshape函数改变形状以匹配图像的尺寸 [高 x 宽 x 通道数]
|
|
|
|
|
# 输入张量的尺度为四维: [(每一)批数据的数目, 高,宽,通道数]
|
|
|
|
|
x = tf.reshape(x, shape=[-1, 28, 28, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 卷积层,32个卷积核,尺寸为5x5
|
|
|
|
|
|