英文:
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
的依赖管理存在许多问题,不幸的是。我尝试了您的代码,出现了稍微不同的导入错误。
您可以尝试以下解决方法:
- 使用最新版本的tensorflow:
pip install tensorflow==2.1.0rc2
- 使用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:
- Use the latest release of tensorflow:
pip install tensorflow==2.1.0rc2
- Use CoLab, where tensorflow and tensorflow_probably are already installed by default: https://colab.sandbox.google.com/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论