前言
Keras序列模型建模的一般步骤:
(1)创建一个Sequential模型;
(2)根据需要,通过“add()”方法在模型中添加所需要的神经网络层, 完成模型构建;
(3)编译模型,通过“compile()”定义模型的训练模式;
(4)训练模型,通过“fit()”方法进行训练模型;
(5)评估模型,通过“evaluate()”进行模型评估;
(6)应用模型,通过“predict()”进行模型预测
1、载入数据
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
print("Tensorflow版本是:",tf.__version__)
mnist = tf.keras.datasets.mnist
(train_images,train_labels),(test_images,test_labels)=mnist.load_data()