tensorflow / tensorflow/probability

Replacing DenseVariational with DenseFlipout does not work

Open
#359 8 comments 2 reactions 1 assignee View on GitHub

@jburnim is already working on this.

Since May 16, 2019.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,
I am trying to replace the DenseVariational layer with DenseFlipout in the Probabilistic Layers Regression Notebook.

Though, this causes model(x_tst).mean().numpy() to fail: AttributeError: 'Tensor' object has no attribute 'numpy'.

  • With DenseVariational or keras.layers.Dense, everything works fine.
  • With DenseReparameterization, DenseLocalReparameterization and DenseFlipout, I get the AttributeError

Am I missing something?

I am using the nightly versions:

tf version: 2.0.0-dev20190405
tfp version: 0.7.0-dev

Here is a minimal example (to run in the Colab):

xs = np.arange(15, dtype=np.float32).reshape((-1, 1))

model = tf.keras.Sequential([
    tfp.layers.DenseFlipout(1),
    tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc=t, scale=1))
])
model.compile(optimizer=tf.optimizers.Adam(learning_rate=0.01), loss=negloglik)
model.fit(xs, xs, epochs=100, verbose=False)

ys = model(xs)
assert isinstance(ys, tfd.Distribution)
print(ys.mean().numpy())  # AttributeError: 'Tensor' object has no attribute 'numpy'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.