在前馈神经网络和卷积神经网络中使用TensorFlow
前馈神经网络的实现与优化
在前馈神经网络(FFNN)的实现中,我们主要关注如何构建模型、优化模型以及评估模型的性能。以下是详细的步骤和相关代码。
1. 定义预测和准确率
首先,我们需要定义正确预测和模型的准确率。代码如下:
correct_prediction = tf.equal(tf.argmax(Y, 1), tf.argmax(Y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
运行模型后,最终测试集的准确率约为97%,输出如下:
>>>
Loading data/train-images-idx3-ubyte.mnist
Loading data/train-labels-idx1-ubyte.mnist
Loading data/t10k-images-idx3-ubyte.mnist
Loading data/t10k-labels-idx1-ubyte.mnist
Epoch: 0
Epoch: 1
Epoch: 2
Epoch: 3
Epoch: 4
Epoch: 5
Epoch: 6
Epoch: 7
Epoch: 8
Epoch: 9
Accuracy: 0.9744
done
>>>
2. 可视化
我们可以使用TensorBoard
超级会员免费看
订阅专栏 解锁全文
3210

被折叠的 条评论
为什么被折叠?



