Skip to content

Commit

Permalink
Update tf.initializers -> tf.keras.initializers.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 576652379
  • Loading branch information
jburnim authored and tensorflower-gardener committed Oct 25, 2023
1 parent c552827 commit b8e04a1
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 82 deletions.
12 changes: 6 additions & 6 deletions tensorflow_probability/python/bijectors/glow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions tensorflow_probability/python/experimental/nn/affine_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(),
Expand All @@ -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: ...
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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,
Expand All @@ -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`.
Expand Down Expand Up @@ -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,
Expand All @@ -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`.
Expand Down Expand Up @@ -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,
Expand All @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=(),
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -278,15 +278,15 @@ 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,
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())
scale = tfp.util.TransformedVariable(1., tfb.Softplus())
bnn = tfn.Sequential([
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down
Loading

0 comments on commit b8e04a1

Please sign in to comment.