【问题标题】:AttributeError: 'KerasRegressor' object has no attribute 'load_weights'AttributeError:“KerasRegressor”对象没有属性“load_weights”
【发布时间】:2020-07-20 12:33:43
【问题描述】:

我已经建立并训练了人工神经网络模型。现在我想加载重量。我使用了 estimator.load_weights(checkpoint_path)。之后我遇到了错误。

AttributeError: 'KerasRegressor' 对象没有属性 'load_weights'

checkpoint_path 完全可以,因为 checkpoint_path = "training_1/cp.ckpt", checkpoint_dir = os.path.dirname(checkpoint_path) 被成功执行 & estimator = KerasRegressor(build_fn=base_model, epochs=1000, batch_size=10, verbose=1)

【问题讨论】:

    标签: python tensorflow keras neural-network


    【解决方案1】:

    estimator 是 Estimator API 的一部分,是 tensorflow model 的包装器。请参阅文档 herethis SO answer 中有关 Estimator API 的有趣讨论。

    load_weights 是一个model 方法。如错误消息中所示,您的估算器是一个 KerasRegressor 对象,它包装了一个模型但不是模型本身。

    您可以使用estimator.model 访问估算器对象的模型属性。

    因此,要加载保存的权重,您可以使用 estimator.model.load_weights(checkpoint_path)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-01
      • 2021-04-19
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多