关于keras分类模型中输入数据与标签维度的案例-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联建站-专业网站定制、快速模板网站建设、高性价比怒江州网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式怒江州网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖怒江州地区。费用合理售后完善,十载实体公司更值得信赖。

小编给大家分享一下关于keras分类模型中输入数据与标签维度的案例,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

在《python深度学习》这本书中。

一、21页mnist十分类

导入数据集
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

初始数据维度:
>>> train_images.shape
(60000, 28, 28)
>>> len(train_labels)
60000
>>> train_labels
array([5, 0, 4, ..., 5, 6, 8], dtype=uint8)

数据预处理:
train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype('float32') / 255
train_labels = to_categorical(train_labels)
  
之后:
print(train_images, type(train_images), train_images.shape, train_images.dtype)
print(train_labels, type(train_labels), train_labels.shape, train_labels.dtype)
结果:
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]  (60000, 784) float32
[[0. 0. 0. ... 0. 0. 0.]
 [1. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 1. 0.]]  (60000, 10) float32

新闻标题:关于keras分类模型中输入数据与标签维度的案例-创新互联
转载源于:http://ybzwz.com/article/pioid.html