解决AttributeError: module 'tensorflow' has no attribute 'ConfigProto':
使用CUDA10.1加上Tensorflow 2.0会出现AttributeError: module 'tensorflow' has no attribute 'ConfigProto'这个问题,这个是由于现在新版本中一些1.0版本的函数被和2.0版本函数区分开的缘故。
需要将
tf.ConfigProto
修改为
tf.compat.v1.ConfigProto
参考blog:https://blog.csdn.net/u012388993/article/details/102573008
解决ModuleNotFoundError: No module named 'tensorflow.contrib':
tf.contrib
doesn't exist in 2.0
参考blog:https://github.com/tensorflow/tensorflow/issues/31350
解决AttributeError: module 'tensorflow' has no attribute 'Session':
tensorflow 2.0版本导致
需要将
tf.Session()
修改为
tf.compat.v1.Session()
参考blog:https://blog.csdn.net/qq_33440324/article/details/94200046
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
AttributeError: module 'tensorflow' has no attribute 'placeholder'等问题的解决
Tensorflow 1.x 版本提供placeholder,而 2.0版本暂时没有这个模块。
If you have this error after an upgrade to TensorFlow 2.0, you can still use 1.X API by replacing:
import tensorflow as tf
with
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
Actually, this modification can help to solve many potential problems.
参考blog: https://stackoverflow.com/questions/37383812/tensorflow-module-object-has-no-attribute-placeholder
tensorflow之tf.contrib.layers.xavier_initializer:
In tensorflow 2.0 you have a package tf.initializer
with all the Keras-like initializers you need.
The Xavier initializer is the same as the Glorot Uniform initializer.
shape = (3,3)
initializer = tf.initializers.GlorotUniform()
var = tf.Variable(initializer(shape=shape))
tf.initializers.GlorotUniform() 可以替代 之前的 tf.contrib.layers.xavier_initializer