Tensorflow实现SoftMax Regression (MNIST)手写体数字识别(增加隐含层提高准确性)

    技术2022-07-10  145

     

    # tensorflow 1.2版本 from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf # 读取本地输入,如果本地没有直接从网上下载 mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) # 输入节点数 in_uint = 784 # 隐藏层节点数 hi_uint = 300 # 定义输入变量:第一层参数和偏执项为w1,b2 第二层参数w2和b2 x = tf.placeholder(tf.float32, [None, in_uint]) w1 = tf.Variable(tf.truncated_normal([in_uint, hi_uint], stddev=0.1)) b1 = tf.Variable(tf.zeros([hi_uint])) w2 = tf.Variable(tf.zeros([hi_uint,10])) b2 = tf.Variable(tf.zeros([10])) # Drop 通过减少隐藏层节点数,达到降采样的目的 keep_prob = tf.placeholder(tf.float32) # 隐藏层:全连接和非线性激活函数 hidden01 = tf.nn.relu(tf.matmul(x, w1) b1) # 隐藏部分节点,达到降采样的目的 hidden01_drop = tf.nn.dropout(hidden01, keep_prob=keep_prob) # 定义前向传播的输出层 y = tf.nn.softmax(tf.matmul(hidden01_drop, w2) b2) # 真实数字类别 y_ = tf.placeholder(tf.float32,[None, 10]) # 定义损失函数&#
    Processed: 0.014, SQL: 9