在使用TensorFlow导入Mnist数据做数字识别训练时,若先导入tensorflow_core.examples.tutorials.mnist,后导入tensorflow,会出现tensorflow中不存在placeholder的报错信息。
tensorflow版本为1.15
AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘

解决方法有两个:
1、直接将import tensorflow as tf 放到第一行,解决!

2、不改变顺序,使用import tensorflow.compat.v1 as tf,解决!

在使用 TensorFlow 1.15 版本进行 Mnist 数据集的数字识别训练时,如果先导入 `tensorflow_core.examples.tutorials.mnist` 后再导入 `tensorflow`,可能会遇到 `AttributeError`,提示 `tensorflow` 模块找不到 `placeholder` 属性。这可以通过两种方式解决:1) 将 `import tensorflow as tf` 放到第一行;2) 使用 `import tensorflow.compat.v1 as tf`。这两种方法都可以确保正确访问 `placeholder` 函数,从而避免报错并继续训练过程。
2万+

被折叠的 条评论
为什么被折叠?



