神经网络_使用tensorflow对fashion mnist衣服数据集分类

from tensorflow import keras 
import matplotlib.pyplot as plt

1.数据预处理

1.1 下载数据集

fashion_mnist = keras.datasets.fashion_mnist
#下载 fashion mnist数据集
(train_images, train_labels),(test_images, test_labels) = fashion_mnist.load_data()

print("train_images shape ", train_images.shape)
print("train_labels shape ", train_labels.shape)
print("train_labels[0] ", train_labels[0])
train_images shape  (60000, 28, 28)
train_labels shape  (60000,)
train_labels[0]  9

1.2展示数据集的第一张图片

plt.figure()
plt.imshow(train_images[0])
plt.colorbar()
plt.grid(False)
plt.show
<function matplotlib.pyplot.show(close=None, block=None)>

在这里插入图片描述

1.3 展示前25张图片和图片名称

train_images = train_images / 255.0;
test_images = test_images / 255.0;

plt.figure(figsize=(10, 10))
class_names = ['T-shirt/top','Trouser','Pullover','Dress','Coat', 
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
print("train_labels ", train_labels[:25])
for i in range(25):
    plt.subplot(5, 5, i+1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(train_images[i], cmap=plt.cm.binary)
    plt.xlabel(class_names[train_labels[i]])
plt.show()
    
train_labels  [9 0 0 3 0 2 7 2 5 5 0 9 5 5 7 9 1 0 6 4 3 1 4 8 4]

在这里插入图片描述

2. 模型实现

2.1模型定义

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值