tensorflow / tensorflow/probability

`tfb.real_nvp_default_template` legacy layers throw error

Open
#1,261 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi,

I am trying to use realnvp in a keras functional API model (tf=2.4.0 and tfp=0.12.1), but this error is thrown:

TypeError: The following are legacy tf.layers.Layers:
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe2636d1310>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe263910520>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe263904250>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243c185e0>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe263531430>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243f5fc40>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe263974eb0>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243ed20a0>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243c3f130>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243ed2b80>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243c18a30>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243ed26a0>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe24410b670>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243ef82b0>
  <tensorflow.python.keras.legacy_tf_layers.core.Dense object at 0x7fe243fb9700>
To use keras as a framework (for instance using the Network, Model, or Sequential classes), please use the tf.keras.layers implementation instead. (Or, if writing custom layers, subclass from tf.keras.layers rather than tf.layers)

I believe these are the lines that should be changed:
https://github.com/tensorflow/probability/blob/92af38538e215063777e531380ca84c076fe1134/tensorflow_probability/python/bijectors/real_nvp.py#L396
https://github.com/tensorflow/probability/blob/92af38538e215063777e531380ca84c076fe1134/tensorflow_probability/python/bijectors/real_nvp.py#L402

shouldn't be a problem to just convert the layers to tf.keras.layers.Dense right? Happy to open a PR if needed.

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.

Research direction

Start in tensorflow_probability/python/bijectors/real_nvp.py at the linked lines around 396 and 402, and inspect how the default RealNVP template creates its Dense layers. Reproduce the reported failure with the TensorFlow 2.4.0 and TensorFlow Probability 0.12.1 setup, then verify that the functional Keras model no longer reports legacy layers.

Written by the indexing model from the issue text.

Assessment

Tech stack
keras, python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.