代码中MNIST_data为真实MNIST数据集的路径
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_integer('is_train', 1, "指定程序预测还是训练")
def fullconnected():
# 获取真实的数据
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
# 1、建立数据的占位符 x [None, 784] y_ture[None, 10]
with tf.variable_scope("data"):
x = tf.placeholder(tf.float32, [None, 784])
y_true = tf.placeholder(tf.int32, [None, 10])
# 2、建立一个全连接层的神经网络 w [784, 10] b[10]
with tf.variable_scope("fc"):
# 随机初始化权重和偏置
weight = tf.Variable(tf.random_normal