Tensorflow:AttributeError: module ‘tensorflow’ has no attribute ‘contrib’解决方案
Tensorflow:AttributeError: module ‘tensorflow’ has no attribute 'contrib’解决方案
遇到问题:
在一次跑相关模型时遇到以下报错
prediction_fn=tf.contrib.layers.softmax,
AttributeError: module ‘tensorflow’ has no attribute ‘contrib’
于是到tensorfolw官网上查contrib模块,
https://tensorflow.google.cn/versions/r1.15/api_docs/python/tf/contrib
看到
意思大概是contrib已经在Tensorflow2.0弃用,它的子模块已经集成到TensorFlow core中,或分拆到TensorFlow_io和tensorflow_addons.有关说明可以查阅迁移指南,但下面那个迁移指南我打不开。
于是我在这个页面搜索layers.softmax的信息,得到如下信息:于是将tf.contrib.layers.softmax改tf.keras.layers.softmax,再次运行没有报错。
据此推测其他有关Tensorflow中contrib的问题也可以用此方法解决。
来源:赤雁麟