2

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

2 Answers 2

3

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/
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but both using colab and updating the version I always get the same error
0

You should find the tensorflow_probability version that suit your tensorflow version, for me it's tensorflow 2.10 and tensorflow_probability 0.16.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.