我搜索了可能的解决方案,并在任何地方都建议使用tf.compat.v1.variable_scope
. 我做了同样的事情,但我得到了错误:
module 'tensorflow' has no attribute 'variable_scope'
我正在使用谷歌 colab。
我的代码:
import tensorflow as tf #version - 2.3.0
with tf.compat.v1.variable_scope(self.name):
self._build()
错误:
---> 45 with tf.compat.v1.variable_scope(self.name):
46 self._build()
47
AttributeError: module 'tensorflow' has no attribute 'variable_scope'
有关如何摆脱此错误的任何建议?我的 TensorFlow 版本是 2.3.0。
编辑:
这是 Astrian_72954 建议的将 TensorFlow 1 代码迁移到 TensorFlow 2中的建议:
每个 v1.variable_scope 都应该转换为 Python 对象。通常这将是以下之一:
tf.keras.layers.Layer tf.keras.Model tf.Module
我不明白这个解决方案。有人可以解释转换为 Python 对象的含义吗?