3

我正在尝试使用 DenseVariational 层构建模型,以便它可以报告认知不确定性。像https://www.tensorflow.org/probability/examples/Probabilistic_Layers_Regression#figure_3_epistemic_uncertainty

模型训练工作得很好,现在我想保存模型并将其加载到生产环境中。但是,当我尝试时model.save('path/model.h5'),我得到了

Layer DenseVariational has arguments in `__init__` and therefore must override `get_config`.

然后我加了

class CustomVariational(tfp.layers.DenseVariational):
  def get_config(self):
        config = super().get_config().copy()
        config.update({
            'units': self.units,
            'make_posterior_fn': self._make_posterior_fn,
            'make_prior_fn': self._make_prior_fn
        })
        return config

但它因新错误而失败

Unable to create link (name already exists)

DenseVariational 层仅用于研究吗?

4

2 回答 2

0

当您添加with tf.name_scope(...)到先验和后验函数时,它应该被解析,否则它们最终对于两个张量具有相同的名称。

我们也在修复示例教程 colab,应该很快就会上线,谢谢。

更新:

我们没有在应用程序中修复它,而是在库中修复它:https ://github.com/tensorflow/probability/commit/0ca065fb526b50ce38b68f7d5b803f02c78c8f16 。更新后,应解析重复的张量名称。谢谢。

于 2022-02-18T22:16:06.360 回答
0

save_weights我认为我们可以通过使用该方法来规避这个问题。

于 2022-01-10T07:56:22.430 回答