【问题标题】:Error when training model in Colab on TPU在 Colab 在 TPU 上训练模型时出错
【发布时间】:2021-01-27 22:10:25
【问题描述】:

我正在尝试使用 TensorFlow 构建 GAN,并希望在 TPU 上对其进行训练。但是我收到下面提到的错误 '确保槽变量是在相同的策略范围下创建的。如果您从范围之外的检查点恢复,则可能会发生这种情况' 我对 TensorFlow 还很陌生。我所有的变量都是用 tf.distribute.experimental.TPUStrategy 创建的

【问题讨论】:

  • 我也没有使用任何检查点。

标签: tensorflow


【解决方案1】:

您正在使用具有自定义层的模型或最新版本的 TensorFlow。如果是这样,load_weights 必须在正确的范围内调用。像这样:

strategy = TPUStrategy(resolver)
with strategy.scope():
    model = ...
    model.compile(...)
    model.load_weights(...)

【讨论】:

    猜你喜欢
    • 2020-12-10
    • 2021-03-22
    • 2020-03-31
    • 2021-05-17
    • 2018-09-25
    • 2019-05-06
    • 2020-02-23
    • 2019-04-20
    • 2022-01-19
    相关资源
    最近更新 更多