tensorflow_probability:AttributeError:module'tensorflow_probability。*没有属性'*'

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

我正在尝试重现我在Google colaboratory(here)上找到的代码片段,但是使用的方法(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笔记本中使用了@tf.function,所以我认为它也使用了tensorflow 2.0.0。

我可以用什么代替?

非常感谢

python-3.x google-colaboratory tensorflow2.0 tensorflow-probability
1个回答
0
投票

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

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

  1. 使用张量流的最新版本:pip install tensorflow==2.1.0rc2
  2. 使用CoLab,默认情况下已经安装了tensorflow和tensorflow_prob:https://colab.sandbox.google.com/
© www.soinside.com 2019 - 2024. All rights reserved.