diff --git a/tensorflow_probability/python/bijectors/glow.py b/tensorflow_probability/python/bijectors/glow.py index a2b4d9727e..e59703ee03 100644 --- a/tensorflow_probability/python/bijectors/glow.py +++ b/tensorflow_probability/python/bijectors/glow.py @@ -859,15 +859,15 @@ def __init__(self, input_shape, num_hidden=400, kernel_shape=3): conv_last = functools.partial( tfkl.Conv2D, padding='same', - kernel_initializer=tf.initializers.zeros(), - bias_initializer=tf.initializers.zeros()) + kernel_initializer=tf.keras.initializers.zeros(), + bias_initializer=tf.keras.initializers.zeros()) super(GlowDefaultNetwork, self).__init__([ tfkl.Input(shape=input_shape), tfkl.Conv2D(num_hidden, kernel_shape, padding='same', - kernel_initializer=tf.initializers.he_normal(), + kernel_initializer=tf.keras.initializers.he_normal(), activation='relu'), tfkl.Conv2D(num_hidden, 1, padding='same', - kernel_initializer=tf.initializers.he_normal(), + kernel_initializer=tf.keras.initializers.he_normal(), activation='relu'), conv_last(this_nchan, kernel_shape) ]) @@ -886,8 +886,8 @@ def __init__(self, input_shape, output_chan, kernel_shape=3): conv = functools.partial( tfkl.Conv2D, padding='same', - kernel_initializer=tf.initializers.zeros(), - bias_initializer=tf.initializers.zeros()) + kernel_initializer=tf.keras.initializers.zeros(), + bias_initializer=tf.keras.initializers.zeros()) super(GlowDefaultExitNetwork, self).__init__([ tfkl.Input(input_shape), diff --git a/tensorflow_probability/python/bijectors/masked_autoregressive.py b/tensorflow_probability/python/bijectors/masked_autoregressive.py index c83cacb48b..fca576dadd 100644 --- a/tensorflow_probability/python/bijectors/masked_autoregressive.py +++ b/tensorflow_probability/python/bijectors/masked_autoregressive.py @@ -1355,8 +1355,8 @@ def _make_masked_initializer(mask, initializer): initializer = tf.keras.initializers.get(initializer) def masked_initializer(shape, dtype=None, partition_info=None): # If no `partition_info` is given, then don't pass it to `initializer`, as - # `initializer` may be a `tf.initializers.Initializer` (which don't accept a - # `partition_info` argument). + # `initializer` may be a `tf.keras.initializers.Initializer` (which don't + # accept a `partition_info` argument). if partition_info is None: x = initializer(shape, dtype) else: diff --git a/tensorflow_probability/python/experimental/nn/affine_layers.py b/tensorflow_probability/python/experimental/nn/affine_layers.py index 578de4ec49..f07aca03dd 100644 --- a/tensorflow_probability/python/experimental/nn/affine_layers.py +++ b/tensorflow_probability/python/experimental/nn/affine_layers.py @@ -45,7 +45,7 @@ def __init__( output_size, # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_kernel_bias_fn=kernel_bias_lib.make_kernel_bias, dtype=tf.float32, batch_shape=(), @@ -61,7 +61,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_kernel_bias_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias`. dtype: ... @@ -179,11 +179,11 @@ def _preprocess(image, label): padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform()) + kernel_initializer=tf.keras.initializers.he_uniform()) BayesAffine = functools.partial( tfn.AffineVariationalReparameterization, - kernel_initializer=tf.initializers.he_normal()) + kernel_initializer=tf.keras.initializers.he_normal()) scale = tfp.util.TransformedVariable(1., tfb.Softplus()) bnn = tfn.Sequential([ @@ -232,7 +232,7 @@ def __init__( output_size, # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -252,7 +252,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. @@ -363,7 +363,7 @@ def __init__( output_size, # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -383,7 +383,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. @@ -502,7 +502,7 @@ def __init__( output_size, # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -522,7 +522,7 @@ def __init__( Default value: `None` (i.e., `tfp.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. diff --git a/tensorflow_probability/python/experimental/nn/convolutional_layers.py b/tensorflow_probability/python/experimental/nn/convolutional_layers.py index 4a34059de1..143a33129f 100644 --- a/tensorflow_probability/python/experimental/nn/convolutional_layers.py +++ b/tensorflow_probability/python/experimental/nn/convolutional_layers.py @@ -91,7 +91,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_kernel_bias_fn=kernel_bias_lib.make_kernel_bias, dtype=tf.float32, batch_shape=(), @@ -147,7 +147,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_kernel_bias_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias`. dtype: ... @@ -288,7 +288,7 @@ def _preprocess(image, label): padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform(), + kernel_initializer=tf.keras.initializers.he_uniform(), penalty_weight=1. / n) BayesAffine = functools.partial( @@ -349,7 +349,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -408,7 +408,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. @@ -538,7 +538,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -597,7 +597,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. diff --git a/tensorflow_probability/python/experimental/nn/convolutional_layers_v2.py b/tensorflow_probability/python/experimental/nn/convolutional_layers_v2.py index 5485833888..48a7108d04 100644 --- a/tensorflow_probability/python/experimental/nn/convolutional_layers_v2.py +++ b/tensorflow_probability/python/experimental/nn/convolutional_layers_v2.py @@ -94,7 +94,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_kernel_bias_fn=kernel_bias_lib.make_kernel_bias, dtype=tf.float32, index_dtype=tf.int32, @@ -151,7 +151,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_kernel_bias_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias`. dtype: ... @@ -288,7 +288,7 @@ def _preprocess(image, label): padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform(), + kernel_initializer=tf.keras.initializers.he_uniform(), penalty_weight=1. / n) BayesAffine = functools.partial( @@ -349,7 +349,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -409,7 +409,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. @@ -549,7 +549,7 @@ def __init__( dilations=1, # keras::Conv::dilation_rate # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -609,7 +609,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. diff --git a/tensorflow_probability/python/experimental/nn/convolutional_transpose_layers.py b/tensorflow_probability/python/experimental/nn/convolutional_transpose_layers.py index 5d2ad4ce14..948ab47000 100644 --- a/tensorflow_probability/python/experimental/nn/convolutional_transpose_layers.py +++ b/tensorflow_probability/python/experimental/nn/convolutional_transpose_layers.py @@ -91,7 +91,7 @@ def __init__( method='auto', # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_kernel_bias_fn=kernel_bias_lib.make_kernel_bias, dtype=tf.float32, index_dtype=tf.int32, @@ -156,7 +156,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_kernel_bias_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias`. dtype: ... @@ -278,7 +278,7 @@ def _preprocess(image, label): padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform()) + kernel_initializer=tf.keras.initializers.he_uniform()) BayesDeconv2D = functools.partial( tfn.ConvolutionTransposeVariationalReparameterization, @@ -286,7 +286,7 @@ def _preprocess(image, label): padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform()) + kernel_initializer=tf.keras.initializers.he_uniform()) scale = tfp.util.TransformedVariable(1., tfb.Softplus()) bnn = tfn.Sequential([ @@ -351,7 +351,7 @@ def __init__( method='auto', # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -420,7 +420,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. @@ -527,14 +527,14 @@ class ConvolutionTransposeVariationalFlipout( padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform()) + kernel_initializer=tf.keras.initializers.he_uniform()) BayesDeconv2D = functools.partial( tfn.ConvolutionTransposeVariationalFlipout, rank=2, padding='same', filter_shape=5, # Use `he_uniform` because we'll use the `relu` family. - kernel_initializer=tf.initializers.he_uniform()) + kernel_initializer=tf.keras.initializers.he_uniform()) ``` This example uses reparameterization gradients to minimize the @@ -567,7 +567,7 @@ def __init__( method='auto', # Weights kernel_initializer=None, # tfp.nn.initializers.glorot_uniform() - bias_initializer=None, # tf.initializers.zeros() + bias_initializer=None, # tf.keras.initializers.zeros() make_posterior_fn=kernel_bias_lib.make_kernel_bias_posterior_mvn_diag, make_prior_fn=kernel_bias_lib.make_kernel_bias_prior_spike_and_slab, posterior_value_fn=tfd.Distribution.sample, @@ -636,7 +636,7 @@ def __init__( Default value: `None` (i.e., `tfp.experimental.nn.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). make_posterior_fn: ... Default value: `tfp.experimental.nn.util.make_kernel_bias_posterior_mvn_diag`. diff --git a/tensorflow_probability/python/experimental/nn/examples/bnn_mnist_advi.ipynb b/tensorflow_probability/python/experimental/nn/examples/bnn_mnist_advi.ipynb index c5ac9827fc..d43067ed41 100644 --- a/tensorflow_probability/python/experimental/nn/examples/bnn_mnist_advi.ipynb +++ b/tensorflow_probability/python/experimental/nn/examples/bnn_mnist_advi.ipynb @@ -229,7 +229,7 @@ " kernel_name='posterior_kernel',\n", " bias_name='posterior_bias'):\n", " if kernel_initializer is None:\n", - " kernel_initializer = tf.initializers.glorot_uniform()\n", + " kernel_initializer = tf.keras.initializers.glorot_uniform()\n", " if bias_initializer is None:\n", " bias_initializer = tf.zeros\n", " make_loc = lambda shape, init, name: tf.Variable( # pylint: disable=g-long-lambda\n", @@ -348,7 +348,7 @@ " output_size=8,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " penalty_weight=1 / train_size,\n", " # penalty_weight=1e2 / train_size, # Layer specific \"beta\".\n", " # make_posterior_fn=make_posterior,\n", @@ -361,7 +361,7 @@ " output_size=16,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " penalty_weight=1 / train_size,\n", " # penalty_weight=1e2 / train_size, # Layer specific \"beta\".\n", " # make_posterior_fn=make_posterior,\n", @@ -375,7 +375,7 @@ " output_size=32,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " penalty_weight=1 / train_size,\n", " # penalty_weight=1e2 / train_size, # Layer specific \"beta\".\n", " # make_posterior_fn=make_posterior,\n", @@ -1207,7 +1207,7 @@ " output_size=8,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " name='conv1'),\n", " maybe_batchnorm,\n", " tf.nn.leaky_relu,\n", @@ -1216,7 +1216,7 @@ " output_size=16,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " name='conv1'),\n", " maybe_batchnorm,\n", " tf.nn.leaky_relu,\n", @@ -1226,7 +1226,7 @@ " output_size=32,\n", " filter_shape=5,\n", " padding='SAME',\n", - " init_kernel_fn=tf.initializers.he_uniform(),\n", + " init_kernel_fn=tf.keras.initializers.he_uniform(),\n", " name='conv2'),\n", " maybe_batchnorm,\n", " tf.nn.leaky_relu,\n", diff --git a/tensorflow_probability/python/experimental/nn/examples/single_column_mnist.ipynb b/tensorflow_probability/python/experimental/nn/examples/single_column_mnist.ipynb index a9e3490f4c..4f95187252 100644 --- a/tensorflow_probability/python/experimental/nn/examples/single_column_mnist.ipynb +++ b/tensorflow_probability/python/experimental/nn/examples/single_column_mnist.ipynb @@ -283,7 +283,7 @@ "\n", " # Convenience function\n", " affine = functools.partial(tfn.Affine,\n", - " init_kernel_fn=tf.initializers.he_normal(),\n", + " init_kernel_fn=tf.keras.initializers.he_normal(),\n", " init_bias_fn = tf.zeros_initializer())\n", "\n", " self._dnn = tfn.Sequential([\n", @@ -333,7 +333,7 @@ "\n", " # Convenience function\n", " affine = functools.partial(tfn.Affine, \n", - " init_kernel_fn=tf.initializers.he_normal(),\n", + " init_kernel_fn=tf.keras.initializers.he_normal(),\n", " init_bias_fn = tf.zeros_initializer())\n", "\n", " # DNN is just an affine transformation for the decoder\n", diff --git a/tensorflow_probability/python/experimental/nn/examples/vae_mnist_advi.ipynb b/tensorflow_probability/python/experimental/nn/examples/vae_mnist_advi.ipynb index a8359220d6..36bf97c7a9 100644 --- a/tensorflow_probability/python/experimental/nn/examples/vae_mnist_advi.ipynb +++ b/tensorflow_probability/python/experimental/nn/examples/vae_mnist_advi.ipynb @@ -240,7 +240,7 @@ "source": [ "Conv = functools.partial(\n", " tfn.Convolution,\n", - " init_kernel_fn=tf.initializers.he_uniform()) # Better for leaky_relu.\n", + " init_kernel_fn=tf.keras.initializers.he_uniform()) # Better for leaky_relu.\n", "\n", "encoder = tfn.Sequential([\n", " lambda x: 2. * tf.cast(x, tf.float32) - 1., # Center.\n", @@ -303,7 +303,7 @@ "source": [ "DeConv = functools.partial(\n", " tfn.ConvolutionTranspose,\n", - " init_kernel_fn=tf.initializers.he_uniform()) # Better for leaky_relu.\n", + " init_kernel_fn=tf.keras.initializers.he_uniform()) # Better for leaky_relu.\n", " \n", "decoder = tfn.Sequential([\n", " lambda x: x[..., tf.newaxis, tf.newaxis, :],\n", diff --git a/tensorflow_probability/python/experimental/nn/examples/vib_dose.ipynb b/tensorflow_probability/python/experimental/nn/examples/vib_dose.ipynb index 2d5c5c7430..11cef0a914 100644 --- a/tensorflow_probability/python/experimental/nn/examples/vib_dose.ipynb +++ b/tensorflow_probability/python/experimental/nn/examples/vib_dose.ipynb @@ -275,7 +275,7 @@ "Conv = functools.partial(\n", " tfn.Convolution,\n", " init_bias_fn=tf.zeros_initializer(),\n", - " init_kernel_fn=tf.initializers.he_uniform()) # Better for leaky_relu.\n", + " init_kernel_fn=tf.keras.initializers.he_uniform()) # Better for leaky_relu.\n", "\n", "encoder = tfn.Sequential([\n", " lambda x: 2. * tf.cast(x, tf.float32) - 1., # Center.\n", @@ -326,11 +326,11 @@ "source": [ "DeConv = functools.partial(\n", " tfn.ConvolutionTranspose,\n", - " init_kernel_fn=tf.initializers.he_uniform()) # Better for leaky_relu.\n", + " init_kernel_fn=tf.keras.initializers.he_uniform()) # Better for leaky_relu.\n", " \n", "Affine = functools.partial(\n", " tfn.Affine,\n", - " init_kernel_fn=tf.initializers.he_uniform())\n", + " init_kernel_fn=tf.keras.initializers.he_uniform())\n", "\n", "decoder = tfn.Sequential([\n", " Affine(encoded_size, 10),\n", diff --git a/tensorflow_probability/python/experimental/nn/util/kernel_bias.py b/tensorflow_probability/python/experimental/nn/util/kernel_bias.py index 55d677f30a..cd331b8c58 100644 --- a/tensorflow_probability/python/experimental/nn/util/kernel_bias.py +++ b/tensorflow_probability/python/experimental/nn/util/kernel_bias.py @@ -58,9 +58,9 @@ def make_kernel_bias( kernel_shape: ... bias_shape: ... kernel_initializer: ... - Default value: `None` (i.e., `tf.initializers.glorot_uniform()`). + Default value: `None` (i.e., `tf.keras.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). kernel_batch_ndims: ... Default value: `0`. bias_batch_ndims: ... @@ -79,13 +79,13 @@ def make_kernel_bias( #### Recommendations: ```python - # tf.nn.relu ==> tf.initializers.he_* - # tf.nn.elu ==> tf.initializers.he_* - # tf.nn.selu ==> tf.initializers.lecun_* - # tf.nn.tanh ==> tf.initializers.glorot_* - # tf.nn.sigmoid ==> tf.initializers.glorot_* - # tf.nn.softmax ==> tf.initializers.glorot_* - # None ==> tf.initializers.glorot_* + # tf.nn.relu ==> tf.keras.initializers.he_* + # tf.nn.elu ==> tf.keras.initializers.he_* + # tf.nn.selu ==> tf.keras.initializers.lecun_* + # tf.nn.tanh ==> tf.keras.initializers.glorot_* + # tf.nn.sigmoid ==> tf.keras.initializers.glorot_* + # tf.nn.softmax ==> tf.keras.initializers.glorot_* + # None ==> tf.keras.initializers.glorot_* # https://towardsdatascience.com/hyper-parameters-in-action-part-ii-weight-initializers-35aee1a28404 # https://stats.stackexchange.com/a/393012/1835 @@ -112,7 +112,7 @@ def make_normal(size): if kernel_initializer is None: kernel_initializer = nn_init_lib.glorot_uniform() if bias_initializer is None: - bias_initializer = tf.initializers.zeros() + bias_initializer = tf.keras.initializers.zeros() return ( tf.Variable(_try_call_init_fn(kernel_initializer, kernel_shape, @@ -156,9 +156,9 @@ def make_kernel_bias_prior_spike_and_slab( kernel_shape: ... bias_shape: ... kernel_initializer: Ignored. - Default value: `None` (i.e., `tf.initializers.glorot_uniform()`). + Default value: `None` (i.e., `tf.keras.initializers.glorot_uniform()`). bias_initializer: Ignored. - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). kernel_batch_ndims: ... Default value: `0`. bias_batch_ndims: ... @@ -200,9 +200,9 @@ def make_kernel_bias_posterior_mvn_diag( kernel_shape: ... bias_shape: ... kernel_initializer: ... - Default value: `None` (i.e., `tf.initializers.glorot_uniform()`). + Default value: `None` (i.e., `tf.keras.initializers.glorot_uniform()`). bias_initializer: ... - Default value: `None` (i.e., `tf.initializers.zeros()`). + Default value: `None` (i.e., `tf.keras.initializers.zeros()`). kernel_batch_ndims: ... Default value: `0`. bias_batch_ndims: ... @@ -220,7 +220,7 @@ def make_kernel_bias_posterior_mvn_diag( if kernel_initializer is None: kernel_initializer = nn_init_lib.glorot_uniform() if bias_initializer is None: - bias_initializer = tf.initializers.zeros() + bias_initializer = tf.keras.initializers.zeros() make_loc = lambda init_fn, shape, batch_ndims, name: tf.Variable( # pylint: disable=g-long-lambda _try_call_init_fn(init_fn, shape, dtype, batch_ndims), name=name + '_loc') diff --git a/tensorflow_probability/python/layers/distribution_layer.py b/tensorflow_probability/python/layers/distribution_layer.py index 82777bbec5..c51fb533a4 100644 --- a/tensorflow_probability/python/layers/distribution_layer.py +++ b/tensorflow_probability/python/layers/distribution_layer.py @@ -1782,7 +1782,7 @@ def __init__( event_shape=(1,), inducing_index_points_initializer=None, unconstrained_observation_noise_variance_initializer=( - tf.initializers.constant(-10.)), + tf.keras.initializers.constant(-10.)), variational_inducing_observations_scale_initializer=None, mean_fn=None, jitter=1e-6, @@ -1869,7 +1869,7 @@ def build(self, input_shape): if self._mean_fn is None: self.mean = self.add_weight( - initializer=tf.initializers.constant([0.]), + initializer=tf.keras.initializers.constant([0.]), dtype=self._dtype, name='mean') self._mean_fn = lambda x: self.mean @@ -1896,14 +1896,14 @@ def build(self, input_shape): self._variational_inducing_observations_loc = self.add_weight( name='variational_inducing_observations_loc', shape=self._event_shape.as_list() + [self._num_inducing_points], - initializer=tf.initializers.zeros(), + initializer=tf.keras.initializers.zeros(), dtype=self._dtype) if self._variational_inducing_observations_scale_initializer is None: eyes = (np.ones(self._event_shape.as_list() + [1, 1]) * np.eye(self._num_inducing_points, dtype=self._dtype)) self._variational_inducing_observations_scale_initializer = ( - tf.initializers.constant(1e-5 * eyes)) + tf.keras.initializers.constant(1e-5 * eyes)) self._variational_inducing_observations_scale = self.add_weight( name='variational_inducing_observations_scale', shape=(self._event_shape.as_list() + diff --git a/tensorflow_probability/python/layers/distribution_layer_test.py b/tensorflow_probability/python/layers/distribution_layer_test.py index 1238fb5e51..663fdf52fb 100644 --- a/tensorflow_probability/python/layers/distribution_layer_test.py +++ b/tensorflow_probability/python/layers/distribution_layer_test.py @@ -1516,7 +1516,7 @@ def __init__(self, **kwargs): super(KernelFn, self).__init__(**kwargs) self._amplitude = self.add_weight( - initializer=tf.initializers.constant(.54), + initializer=tf.keras.initializers.constant(.54), dtype=dtype, name='amplitude') @@ -1533,7 +1533,7 @@ def kernel(self): # Add a leading dimension for the event_shape. eyes = np.expand_dims(np.eye(num_inducing_points), 0) variational_inducing_observations_scale_initializer = ( - tf.initializers.constant(1e-3 * eyes)) + tf.keras.initializers.constant(1e-3 * eyes)) model = tf.keras.Sequential([ tf.keras.layers.InputLayer(input_shape=[1], dtype=dtype), @@ -1543,7 +1543,7 @@ def kernel(self): num_inducing_points=num_inducing_points, kernel_provider=KernelFn(dtype=dtype), inducing_index_points_initializer=( - tf.initializers.constant( + tf.keras.initializers.constant( np.linspace(*x_range, num=num_inducing_points, dtype=dtype)[..., np.newaxis])), diff --git a/tensorflow_probability/python/layers/initializers.py b/tensorflow_probability/python/layers/initializers.py index 0ebe5fdf69..52a092d0bb 100644 --- a/tensorflow_probability/python/layers/initializers.py +++ b/tensorflow_probability/python/layers/initializers.py @@ -103,7 +103,7 @@ def get_config(self): """Returns initializer configuration as a JSON-serializable dict.""" return { 'initializers': [ - tf.initializers.serialize( + tf.keras.initializers.serialize( tf.keras.initializers.get(init)) for init in self.initializers ], @@ -115,7 +115,7 @@ def get_config(self): def from_config(cls, config): """Instantiates an initializer from a configuration dictionary.""" return cls(**{ - 'initializers': [tf.initializers.deserialize(init) + 'initializers': [tf.keras.initializers.deserialize(init) for init in config.get('initializers', [])], 'sizes': config.get('sizes', []), 'validate_args': config.get('validate_args', False), diff --git a/tensorflow_probability/python/layers/initializers_test.py b/tensorflow_probability/python/layers/initializers_test.py index 91fc165a2e..8148df0b78 100644 --- a/tensorflow_probability/python/layers/initializers_test.py +++ b/tensorflow_probability/python/layers/initializers_test.py @@ -34,9 +34,9 @@ def test_works_correctly(self): self.assertAllEqual(np.zeros([2, 1, 4]), x_[..., 3:]) def test_de_serialization(self): - s = tf.initializers.serialize( + s = tf.keras.initializers.serialize( initializers.BlockwiseInitializer(['glorot_uniform', 'zeros'], [3, 4])) - init_clone = tf.initializers.deserialize(s) + init_clone = tf.keras.initializers.deserialize(s) x = init_clone([2, 1, 7]) self.assertEqual((2, 1, 7), x.shape) x_ = self.evaluate(x)