【发布时间】:2020-08-06 10:35:57
【问题描述】:
我搜索了可能的解决方案,并且在任何地方都建议使用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 建议的 Migrate your TensorFlow 1 code to TensorFlow 2 中的建议:
每个 v1.variable_scope 都应该转换为 Python 对象。 通常这将是以下之一:
tf.keras.layers.Layer tf.keras.Model tf.Module
我不明白这个解决方案。有人能解释一下转换为 Python 对象是什么意思吗?
【问题讨论】:
-
这是一个纯粹的
tensorflow和tensorflow2问题,它实际上与machine-learning或deep-learning无关——请不要编辑回标签(已删除)。跨度>
标签: python tensorflow tensorflow2