python - AttributeError:模块 'keras.datasets.fashion_mnist' 没有属性 'shape'
问题描述
我一直在尝试使用 google colab 在时尚 mnist 数据集上实现 SVM,并不断收到上述错误。这里可能是什么问题?
import keras
from keras.datasets import fashion_mnist
data = keras.datasets.fashion_mnist
nsamples, nx, ny = data.shape
解决方案
要重塑您的数据,您应该替换这部分代码:
data = keras.datasets.fashion_mnist
nsamples, nx, ny = data.shape
data = data.reshape(nsamples,nx*ny)
(xtrain, ytrain), (xtest, ytest) = data.load_data()
convert(xtrain, ytrain)
convert(xtest, ytest)
有了这个:
(xtrain, ytrain), (xtest, ytest) = keras.datasets.fashion_mnist.load_data()
# xtrain.shape = (60000,28,28) before reshaping
xtrain = xtrain.reshape(xtrain.shape[0],(xtrain.shape[1] * xtrain.shape[2]))
# xtrain.shape = (60000,784) after reshaping
# xtest.shape = (10000,28,28) before reshaping
xtest = xtest.reshape(xtest.shape[0],(xtest.shape[1] * xtest.shape[2]))
# xtest.shape = (10000,784) after reshaping
convert(xtrain, ytrain)
convert(xtest, ytest)
推荐阅读
- python - Tensorflow 到 Keras:在 Keras 模型上导入图定义错误
- angular - 更新到 Angular 6.1 后的路由问题
- python - 谷歌表python脚本条件格式自定义公式
- audio - FFmpeg:如何在 ffmpeg 中快速应用音量过滤器
- sql - 在 SQL 中使用 Over & Partition
- c - 关于链表结构的语法问题
- oracle - Oracle APEX 交互式报告中的错误 - ORA-01427:单行子查询返回多于一行
- spring - Sping MVC和hibernate:jsp中未声明的变量在保存时变为null
- ios - 我的应用程序没有执行我编写的 Swift 代码
- node.js - TypeScript:仅在单元测试中找不到模块的声明文件