Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layer.add_variable is deprecated #1702

Open
ThexXTURBOXx opened this issue Mar 4, 2023 · 0 comments · May be fixed by #1703
Open

layer.add_variable is deprecated #1702

ThexXTURBOXx opened this issue Mar 4, 2023 · 0 comments · May be fixed by #1703

Comments

@ThexXTURBOXx
Copy link

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)
@ThexXTURBOXx ThexXTURBOXx linked a pull request Mar 4, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant