解决AttributeError: module 'tensorflow' has no attribute 'contrib'的问题

1,630 阅读1分钟

我是从GitHub上下载的基于TensorFlow 1版本的bert代码,我本身的环境是TensorFlow 2版本,所以运行的时候有很多错,在改AttributeError: module 'tensorflow' has no attribute 'contrib'这个错误的时候,发现并没有像之前加一句compat.v1就可以解决,上网搜索发现,contrib被集成到其他几个包文件里了。

大家可以点击下方链接进入官网详细查询:

tensorflow.google.cn/versions/r1…

问题截图:

图片.png

定位到原文发现有这么多contrib:

图片.png

去官网上找相关包,比如我要找这个

tf.contrib.tpu.InputPipelineConfig

那我就要先点击tpu再点击InputPipelineConfig,然后进入到下面界面:

图片.png

最后复制粘贴就OK了