tensorflow_probability: AttributeError: 模块 ‘tensorflow_probability.*’ 没有属性 ‘*’

huangapple go评论54阅读模式
英文:

tensorflow_probability: AttributeError: module 'tensorflow_probability.* has no attribute '*'

问题

我试图复现我在Google Colaboratory上找到的一段代码(这里),但我在使用的方法(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。

我应该使用什么替代方法?

非常感谢!

英文:

I'm trying to reproduce a snippet of code I found on google colaboratory (here) and I have problems with the methods used (tfb.Shift and tfp.util.TransformedVariable) that I can't find in the documentation.

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)

I get

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

and

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

Could be a version issue?

I'm using tensorflow 2.0.0 and tensorflow-probability 0.8.0 and I see that in colab notebook is used @tf.function so I thought it used tensorflow 2.0.0 too.

What can I use instead?

Thank you very much

答案1

得分: 3

似乎tensorflow_probability的依赖管理存在许多问题,不幸的是。我尝试了您的代码,出现了稍微不同的导入错误。

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

  1. 使用最新版本的tensorflow:pip install tensorflow==2.1.0rc2
  2. 使用CoLab,在那里tensorflow和tensorflow_probably已经默认安装了:https://colab.sandbox.google.com/
英文:

It seems there are lot of issues in tensorflow_probability's dependency management, unfortunately. I tried your code and got a slightly different import error.

You can try the following workarounds:

  1. Use the latest release of tensorflow: pip install tensorflow==2.1.0rc2
  2. Use CoLab, where tensorflow and tensorflow_probably are already installed by default: https://colab.sandbox.google.com/

huangapple
  • 本文由 发表于 2020年1月3日 20:01:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定