GPFlow:“NaturalGradient”对象没有属性“_name”

问题描述 投票:0回答:0

我试图从 GPFlow 库站点复制异方差似然和多潜在 GP 示例。除了“运行优化循环”下的最后一段代码外,一切都运行良好,并抛出错误:

AttributeError: 'NaturalGradient' object has no attribute '_name'
.

问题:我能做些什么来解决这个问题吗?

要运行的代码

epochs = 100
log_freq = 20

for epoch in range(1, epochs + 1):
    optimisation_step()

    # For every 'log_freq' epochs, print the epoch and plot the predictions against the data
    if epoch % log_freq == 0 and epoch > 0:
        print(f"Epoch {epoch} - Loss: {loss_fn().numpy() : .4f}")
        Ymean, Yvar = model.predict_y(X)
        Ymean = Ymean.numpy().squeeze()
        Ystd = tf.sqrt(Yvar).numpy().squeeze()
        plot_distribution(X, Y, Ymean, Ystd)

model

包的版本

print(tf.__version__) --> 2.11.0
print(tfp.__version__) --> 0.19.0
print(gf.__version__) --> 2.7.1

更多详情

更多错误信息如下:

AttributeError                            Traceback (most recent call last)
<ipython-input-11-aee9c220de71> in <module>
      3 
      4 for epoch in range(1, epochs + 1):
----> 5     optimisation_step()

...并继续

/usr/local/lib/python3.9/dist-packages/gpflow/optimizers/natgrad.py in tf___natgrad_steps(self, loss_fn, parameters)
     21                     loss = ag__.converted_call(ag__.ld(loss_fn), (), None, fscope)
     22                 (q_mu_grads, q_sqrt_grads) = ag__.converted_call(ag__.ld(tape).gradient, (ag__.ld(loss), [ag__.ld(q_mu_vars), ag__.ld(q_sqrt_vars)]), None, fscope)
---> 23                 with ag__.ld(tf).name_scope(f'{ag__.ld(self)._name}/natural_gradient_steps'):
     24 
     25                     def get_state():

AttributeError: in user code:

    File "<ipython-input-10-2722f09bae9a>", line 16, in optimisation_step  *
        natgrad_opt.minimize(loss_fn, variational_vars)
    File "/usr/local/lib/python3.9/dist-packages/check_shapes/integration/tf.py", line 208, in wrapped_method  *
        return wrapped_function(self, *args, **kwargs)
    File "/usr/local/lib/python3.9/dist-packages/check_shapes/decorator.py", line 120, in wrapped_function  *
        return func(*args, **kwargs)
    File "/usr/local/lib/python3.9/dist-packages/gpflow/optimizers/natgrad.py", line 236, in minimize  *
        self._natgrad_steps(loss_fn, parameters)
    File "/usr/local/lib/python3.9/dist-packages/check_shapes/integration/tf.py", line 208, in wrapped_method  *
        return wrapped_function(self, *args, **kwargs)
    File "/usr/local/lib/python3.9/dist-packages/check_shapes/decorator.py", line 120, in wrapped_function  *
        return func(*args, **kwargs)
    File "/usr/local/lib/python3.9/dist-packages/gpflow/optimizers/natgrad.py", line 266, in _natgrad_steps  *
        with tf.name_scope(f"{self._name}/natural_gradient_steps"):

    AttributeError: 'NaturalGradient' object has no attribute '_name'

我尝试将 Tensorflow 更改为旧版本,但没有用。我还尝试查看 NaturalGradient 的 GPFlow 源代码,但恐怕这并没有帮助我找到解决方案。

python tensorflow attributes gaussian-process gpflow
© www.soinside.com 2019 - 2024. All rights reserved.