tensorflow / tensorflow/probability
layer.add_variable is deprecated
Open
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I am currently trying to implement a Bayesian Neural Network for image classification. However, two warnings are raised:
/usr/local/lib/python3.10/dist-packages/tensorflow_probability/python/layers/util.py:95: UserWarning: `layer.add_variable` is deprecated and will be removed in a future version. Please use the `layer.add_weight()` method instead.
loc = add_variable_fn(
/usr/local/lib/python3.10/dist-packages/tensorflow_probability/python/layers/util.py:105: UserWarning: `layer.add_variable` is deprecated and will be removed in a future version. Please use the `layer.add_weight()` method instead.
untransformed_scale = add_variable_fn(
I am currently using the following code:
bayesian_model = Sequential([
tfpl.Convolution2DReparameterization(input_shape=(512, 512, 1), filters=8, kernel_size=16, activation='relu',
kernel_prior_fn=tfpl.default_multivariate_normal_fn,
kernel_posterior_fn=tfpl.default_mean_field_normal_fn(is_singular=False),
kernel_divergence_fn=divergence_fn,
bias_prior_fn=tfpl.default_multivariate_normal_fn,
bias_posterior_fn=tfpl.default_mean_field_normal_fn(is_singular=False),
bias_divergence_fn=divergence_fn),
Conv2D(kernel_size=(5, 5), filters=8, activation='relu', padding='VALID'),
MaxPooling2D(pool_size=(6, 6)),
Flatten(),
Dropout(0.2),
tfpl.DenseReparameterization(units=tfpl.OneHotCategorical.params_size(3), activation=None,
kernel_prior_fn=tfpl.default_multivariate_normal_fn,
kernel_posterior_fn=tfpl.default_mean_field_normal_fn(is_singular=False),
kernel_divergence_fn=divergence_fn,
bias_prior_fn=tfpl.default_multivariate_normal_fn,
bias_posterior_fn=tfpl.default_mean_field_normal_fn(is_singular=False),
bias_divergence_fn=divergence_fn
),
tfpl.OneHotCategorical(3)
])
bayesian_model.compile(loss=negative_log_likelihood,
optimizer=Adam(learning_rate=0.005),
metrics=['accuracy'],
experimental_run_tf_function=False)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tensorflow_probability/python/layers/util.py at the warning locations around lines 95 and 105, using the reported add_variable deprecation as the entry point. Update the affected behavior to remove these warnings and verify the Bayesian layer paths still work with the relevant existing checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100