【问题标题】:tensorflow_probability: AttributeError: module 'tensorflow_probability.* has no attribute '*'tensorflow_probability:AttributeError:模块'tensorflow_probability.*没有属性'*'
【发布时间】:2020-04-22 00:00:51
【问题描述】:

我正在尝试重现我在 google colaboratory (here) 上找到的代码 sn-p,但我使用的方法(tfb.Shift 和 tfp.util.TransformedVariable)有问题,我找不到在文档中。

import numpy as np
import tensorflow.compat.v2 as tf
import tensorflow_probability as tfp
tfb = tfp.bijectors
tfd = tfp.distributions
tf.enable_v2_behavior()

constrain_positive = tfb.Shift(np.finfo(np.float64).tiny)(tfb.Exp())

amplitude_var = tfp.util.TransformedVariable(
    initial_value=1.,
    bijector=constrain_positive,
    name='amplitude',
    dtype=np.float64)

我明白了

AttributeError: module 'tensorflow_probability.python.bijectors' has no attribute 'Shift'

AttributeError: module 'tensorflow_probability.python.util' has no attribute 'TransformedVariable'

可能是版本问题?

我正在使用 tensorflow 2.0.0 和 tensorflow-probability 0.8.0,我看到在 colab notebook 中使用了 @tf.function,所以我认为它也使用了 tensorflow 2.0.0。

我可以用什么代替?

非常感谢

【问题讨论】:

    标签: python-3.x google-colaboratory tensorflow2.0 tensorflow-probability


    【解决方案1】:

    不幸的是,tensorflow_probability 的依赖管理似乎存在很多问题。我尝试了您的代码,但导入错误略有不同。

    您可以尝试以下解决方法:

    1. 使用最新发布的tensorflow:pip install tensorflow==2.1.0rc2
    2. 使用 CoLab,其中 tensorflow 和 tensorflow_probably 已经默认安装:https://colab.sandbox.google.com/

    【讨论】:

    • 谢谢,但无论是使用 colab 还是更新版本,我总是遇到同样的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 2021-12-24
    • 2015-05-08
    • 2020-10-17
    • 2020-10-03
    • 2018-08-11
    • 2020-01-01
    相关资源
    最近更新 更多