当尝试加载BERT QA时,出现以下ImportError: “无法从'tensorflow.python.keras.engine'导入名称'网络'” 完整的错误日志如下
此帖子之后, ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine'
我尝试了以下步骤,
pip uninstall tf-agents
pip install tf-agents-nightly
然后在Python中
from tf_agents.environments import suite_gym
但是,这不能解决问题。任何建议将非常欢迎!
如果有帮助,我正在运行TensorFlow版本2.3.0。另外,下面提到的脚本 init .py确实存在,但是文件为空,即0个字节。
ImportError Traceback (most recent call last)
<ipython-input-2-323bac0cb5ba> in <module>
----> 1 from bert_qa import squad
~/anaconda3/lib/python3.8/site-packages/bert_qa/squad.py in <module>
34 from . import model_training_utils
35 from . import bert_modeling as modeling
---> 36 from . import bert_models
37 from . import optimization
38 from . import input_pipeline
~/anaconda3/lib/python3.8/site-packages/bert_qa/bert_models.py in <module>
25 from . import bert_modeling
26 from . import weighted_sparse_categorical_crossentropy
---> 27 from . transformer_encoder import TransformerEncoder
28 from . albert_transformer_encoder import AlbertTransformerEncoder
29 from . import bert_classifier
~/anaconda3/lib/python3.8/site-packages/bert_qa/transformer_encoder.py in <module>
22 import tensorflow as tf
23
---> 24 from tensorflow.python.keras.engine import network # pylint: disable=g-direct-tensorflow-import
25
26 from . import activations
ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (/home/user810643/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/__init__.py)
答案 0 :(得分:0)
为 Tebsorflow 2.3 安装 tf-agents 0.6.0 版本。
pip install tf-agents==0.6.0
看起来这个问题是由于 TF-Agents 和 Tensorflow 版本不兼容造成的。有关详细信息,请查看此 release 注释。谢谢!