tensorflow搭建卷积神经网络非常简单,我们使用卷积神经网络对fashion mnist数据集进行图片分类,首先导包:
import tensorflow as tf from tensorflow import keras import matplotlib.pyplot as plt import numpy as np
导入数据集:
(train_image,train_label),(test_image,test_label)=tf.keras.datasets.fashion_mnist.load_data()
查看图片的shape维度:
train_image.shape
输出:
(60000, 28, 28)
由于我们卷积神经网络需要的是四维的数据,也就是一共需要有四个维度,分别是(图片,横向像素,竖直方向的像素,channel)。
这个数据集里面的图像均为三维的矩阵,且为黑白图片,因此channel为1,如果是RGB的彩色图片的话,channel为3.因此我们把三维的图片变成4维的图片,利用numpy即可:
<