tensorflow - 模块“tensorflow.keras.datasets.mnist”没有属性“x_train”
问题描述
在下载 MNIST 数据集并将其加载到各自的变量中后,我尝试打印 x_tain、x_test、y_train、y_test 的值。然后它向我展示了这个错误。
import tensorflow as tf
import matplotlib.pyplot as plt
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print("No of labels in training set {}".format(mnist.y_train.labels.shape))
print("No of images in test set {}".format(mnist.x_test.images.shape))
print("No of labels in test set {}".format(mnist.y_test.labels.shape))
print("No of images in training set {}".format(mnist.x_train.images.shape))
执行后显示如下错误
module 'tensorflow.keras.datasets.mnist' has no attribute 'x_train'
解决方案
tf.keras.datasets.mnist
除了 .module 之外,确实没有任何其他成员load_data
。因此,在加载值之前到处添加模块名称mnist
是没有意义的。您加载了您的数据,(x_train, y_train), (x_test, y_test)
并且您可以使用它们。不需要mnist.y_train
,只需使用y_train
推荐阅读
- owasp - 如何在 OWASP ZAP 中使用除英语之外的其他语言生成报告(例如 html 报告)?
- java - 一个骰子和第二个骰子的总面数无法正常工作的骰子程序
- javascript - 为什么可变路由路径在 Express.js 中不起作用并给出错误?
- python - 如何有效地合并两个 protobuf 文件?
- emacs - 如何在适当的时候使用“~/”提示 helm-find-files,而不是扩展路径?
- windows - 如何识别进程正在使用分配的虚拟内存的哪些部分
- c# - 如何优先使用使用 xunit runner 运行的 specflow/xunit 的 BDD
- javascript - Javascript - 检测 div 的滚动,工作,但不工作
- flutter - 网址在发布 apk 时无法解析,但在调试时无法解析
- javascript - 使用 Click 或 Escape 键调用 setState