参考: BP神经网络
1.前言
BP神经网络是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。
BP神经网络,系统解决了多层神经网络隐含层连接权学习问题。从结构上讲,BP网络具有输入层、隐藏层和输出层;从本质上讲,BP算法就是均方误差为目标函数,采用梯度下降法来计算目标函数的最小值。
2.问题描述
使用BP神经网络识别MNIST手写数字数据集
3.BP神经网络的Tensorflow实现
在Tensorflow2.0中,对于经典的BP神将网络进行了封装,称为全连接层,它会自动完成BP神经网络隐层的操作
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author: liujie
@software: PyCharm
@file: 手写数据集.py
@time: 2020/11/10 14:06
"""
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import optimizers,datasets,layers,Sequential,metrics
(x,y) ,(x_test,y_test) = datasets.fashion_mnist.load_data()
print(x.shape,y.shape)
# 数据处理
def preprocess(x,y):
x = tf.cast(x,dtype=tf.float32) / 255.
y = tf.cast(y,dtype=tf.int32)
return x,y
batch_size = 64