试试MNIST For ML Beginners代码

和光启
2023-12-01

网址是:https://www.tensorflow.org/get_started/mnist/beginners

个人觉得需要解释的地方,等哪天做个视频玩玩

引进数据集:mnist = input_data.read_data_sets(“MNIST_data/”,one_hot=True)
one_hot表示法0=(1,0,0),1=(0,1,0),2=(0,0,1)。

评估函数cross-entropy:
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
用log是为了区分0.9和0.99这种y值。reduction_indices参数的意思:https://www.cnblogs.com/likethanlove/p/6547405.html。就是按照哪个维度相加,默认加成一个数。

accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
函数tf.cast(a,bool):将a转换为bool型。

 类似资料: