【发布时间】: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