python - 错误:即使将 tensorflow 导入为 tensorflow.compat.v1 后,模块“tensorflow”也没有属性“gfile”
问题描述
我已经阅读了这个问题的解决方案,其中 tensorflow 版本更改为 1.14 对人们有用。我想知道是否有任何其他解决方案而不进行版本更改。我正在使用 Jupyter 工作,并且正在运行使用 2.4.1 版的程序。我试图避免版本更改的其他原因是,一旦我将其更改为 1.14,还有其他功能(如句子和其他功能)会产生后续错误。
我正在尝试使用来自 github 的代码运行 BERT 模型。 https://github.com/google-research/bert
错误在 tokenization.py 函数中
~\bert\tokenization.py in load_vocab(vocab_file)
123 """Loads a vocabulary file into a dictionary."""
124 vocab = collections.OrderedDict()
125 index = 0
126 with tf.io.gfile.GFile(vocab_file, "r") as reader:
AttributeError:模块“tensorflow”没有属性“gfile”
任何建议都非常感谢!
更新:即使我不使用 tf.io.gfile.GFile 并尝试使用“with open(json_file, 'r') as reader:”,奇怪的是我得到了同样的错误。这很奇怪。
\bert\modeling.py in from_json_file(cls, json_file)
91 def from_json_file(cls, json_file):
92 """Constructs a `BertConfig` from a json file of
parameters."""
93 print(cls)
94 print(json_file)
95 with open(json_file, 'r') as reader:
AttributeError:模块“tensorflow”没有属性“gfile”。如果您看到我完全看不到的东西,请告诉我。
解决方案
推荐阅读
- java - 向 PC 未安装 Java 的用户发送 Java 程序
- jenkins - 在 Jenkins Execute Shell 脚本块中转义单引号
- python - How to specify status code in Google Cloud Function response?
- python-3.x - cron 是否监视作业的退出代码,我有一个正在重新启动的 cron 作业
- c - 我正在尝试用 c 语言读取文件,文件结构在数组中,我必须将它分成数组 x[] 和 y[]
- python - 获取 Django - [Errno 111] 连接被拒绝错误
- javascript - 使用 formData 上传文件时输入错误
- r - `rlang::exec` 因 `WRS2::rmmcp` 失败
- mysql - Mysql递归选择并附加所有子项(如果存在)
- reactjs - API 现在返回部分数据并稍后返回部分数据的惯用方式是什么?