tensorflow 2版本读取MNIST数据集,使用 read_data_sets,在导入时报错

from tensorflow.examples.tutorials.mnist import input_data
AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'

查网上说法是tf2版本已经弃用了read_data_sets,但我这个报错原因不知道是不是因为这个,总之在导入时就出错
解决:换如下加载MNIST方法:

import tensorflow as tf

mnist = tf.keras.datasets.mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐