import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/hds/books/studybook/workspace/MNIST_data", one_hot=True)
batch_size = 100 # 设置每一轮训练的batch大小
learning_rate = 0.8 # 学习率
learning_rate_decay = 0.999 # 学习率的衰减
max_steps = 30000 # 最大训练步数
# 定义存储训练轮数的变量,在使用Tensorflow训练神经网络时,
# 一般会将代表训练轮数的变量通过trainable参数设置为不可训练的
training_step = tf.Variable(0, trainable=False)
# 定义得到隐藏层和输出层的前向传播计算方式,激活函数使用relu()
def hidden_layer(input_tensor, weights1, biases1, weights2, biases2, layer_name):
layer1 = tf.nn.relu(tf.matmul(input_tensor, weights1)+biases1)
return tf.matmul(layer1, weights2)+biases2
x = tf.placeholder(tf.float32, [None, 784], name="x-input") # INPUT_NODE=784
y_ = tf.placeholder(tf.float32, [None, 10], name="y-output")
MNIST数据集训练(1)98.5%
最新推荐文章于 2022-10-15 20:22:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)