class_docstr: 2D convolution layer (e.g. spatial convolution over images) with Flipout.
  
  This layer creates a convolution kernel that is convolved
  (actually cross-correlated) with the layer input to produce a tensor of
  outputs. It may also include a bias addition and activation function
  on the outputs. It assumes the `kernel` and/or `bias` are drawn from
  distributions.
  
  By default, the layer implements a stochastic forward pass via
  sampling from the kernel and bias posteriors,
  ```none
  outputs = f(inputs; kernel, bias), kernel, bias ~ posterior
  ```
  where f denotes the layer's calculation. It uses the Flipout
  estimator [(Wen et al., 2018)][1], which performs a Monte Carlo approximation
  of the distribution integrating over the `kernel` and `bias`. Flipout uses
  roughly twice as many floating point operations as the reparameterization
  estimator but has the advantage of significantly lower variance.
  
  The arguments permit separate specification of the surrogate posterior
  (`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
  distributions.
  
  Upon being built, this layer adds losses (accessible via the `losses`
  property) representing the divergences of `kernel` and/or `bias` surrogate
  posteriors and their respective priors. When doing minibatch stochastic
  optimization, make sure to scale this loss such that it is applied just once
  per epoch (e.g. if `kl` is the sum of `losses` for each element of the batch,
  you should pass `kl / num_examples_per_epoch` to your optimizer).
  
  #### Examples
  
  We illustrate a Bayesian neural network with [variational inference](
  https://en.wikipedia.org/wiki/Variational_Bayesian_methods),
  assuming a dataset of `features` and `labels`.
  
  ```python
  import tensorflow as tf
  import tensorflow_probability as tfp
  
  model = tf_keras.Sequential([
      tf_keras.layers.Reshape([32, 32, 3]),
      tfp.layers.Convolution2DFlipout(
          64, kernel_size=5, padding='SAME', activation=tf.nn.relu),
      tf_keras.layers.MaxPooling2D(pool_size=[2, 2],
                                   strides=[2, 2],
                                   padding='SAME'),
      tf_keras.layers.Flatten(),
      tfp.layers.DenseFlipout(10),
  ])
  
  logits = model(features)
  neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(
      labels=labels, logits=logits)
  kl = sum(model.losses)
  loss = neg_log_likelihood + kl
  train_op = tf.train.AdamOptimizer().minimize(loss)
  ```
  
  It uses the Flipout gradient estimator to minimize the
  Kullback-Leibler divergence up to a constant, also known as the
  negative Evidence Lower Bound. It consists of the sum of two terms:
  the expected negative log-likelihood, which we approximate via
  Monte Carlo; and the KL divergence, which is added via regularizer
  terms which are arguments to the layer.
  
  #### References
  
  [1]: Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, and Roger Grosse. Flipout:
       Efficient Pseudo-Independent Weight Perturbations on Mini-Batches. In
       _International Conference on Learning Representations_, 2018.
       https://arxiv.org/abs/1803.04386
class_docstr_tok: ["2D","convolution","layer","(","e.g",".","spatial","convolution","over","images",")","with","Flipout",".","This","layer","creates","a","convolution","kernel","that","is","convolved","(","actually","cross-correlated",")","with","the","layer","input","to","produce","a","tensor","of","outputs",".","It","may","also","include","a","bias","addition","and","activation","function","on","the","outputs",".","It","assumes","the","`","kernel","`","and\/or","`","bias","`","are","drawn","from","distributions",".","By","default",",","the","layer","implements","a","stochastic","forward","pass","via","sampling","from","the","kernel","and","bias","posteriors",",","``","`","none","outputs","=","f","(","inputs",";","kernel",",","bias",")",",","kernel",",","bias","~","posterior","``","`","where","f","denotes","the","layer","'s","calculation",".","It","uses","the","Flipout","estimator","[","(","Wen","et","al.",",","2018",")","]","[","1","]",",","which","performs","a","Monte","Carlo","approximation","of","the","distribution","integrating","over","the","`","kernel","`","and","`","bias","`",".","Flipout","uses","roughly","twice","as","many","floating","point","operations","as","the","reparameterization","estimator","but","has","the","advantage","of","significantly","lower","variance",".","The","arguments","permit","separate","specification","of","the","surrogate","posterior","(","`","q","(","W|x",")","`",")",",","prior","(","`","p","(","W",")","`",")",",","and","divergence","for","both","the","`","kernel","`","and","`","bias","`","distributions",".","Upon","being","built",",","this","layer","adds","losses","(","accessible","via","the","`","losses","`","property",")","representing","the","divergences","of","`","kernel","`","and\/or","`","bias","`","surrogate","posteriors","and","their","respective","priors",".","When","doing","minibatch","stochastic","optimization",",","make","sure","to","scale","this","loss","such","that","it","is","applied","just","once","per","epoch","(","e.g",".","if","`","kl","`","is","the","sum","of","`","losses","`","for","each","element","of","the","batch",",","you","should","pass","`","kl","\/","num_examples_per_epoch","`","to","your","optimizer",")",".","#","#","#","#","Examples","We","illustrate","a","Bayesian","neural","network","with","[","variational","inference","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Variational_Bayesian_methods",")",",","assuming","a","dataset","of","`","features","`","and","`","labels","`",".","``","`","python","import","tensorflow","as","tf","import","tensorflow_probability","as","tfp","model","=","tf_keras.Sequential","(","[","tf_keras.layers.Reshape","(","[","32",",","32",",","3","]",")",",","tfp.layers.Convolution2DFlipout","(","64",",","kernel_size=5",",","padding='SAME","'",",","activation=tf.nn.relu",")",",","tf_keras.layers.MaxPooling2D","(","pool_size=","[","2",",","2","]",",","strides=","[","2",",","2","]",",","padding='SAME","'",")",",","tf_keras.layers.Flatten","(",")",",","tfp.layers.DenseFlipout","(","10",")",",","]",")","logits","=","model","(","features",")","neg_log_likelihood","=","tf.nn.softmax_cross_entropy_with_logits","(","labels=labels",",","logits=logits",")","kl","=","sum","(","model.losses",")","loss","=","neg_log_likelihood","+","kl","train_op","=","tf.train.AdamOptimizer","(",")",".minimize","(","loss",")","``","`","It","uses","the","Flipout","gradient","estimator","to","minimize","the","Kullback-Leibler","divergence","up","to","a","constant",",","also","known","as","the","negative","Evidence","Lower","Bound",".","It","consists","of","the","sum","of","two","terms",":","the","expected","negative","log-likelihood",",","which","we","approximate","via","Monte","Carlo",";","and","the","KL","divergence",",","which","is","added","via","regularizer","terms","which","are","arguments","to","the","layer",".","#","#","#","#","References","[","1","]",":","Yeming","Wen",",","Paul","Vicol",",","Jimmy","Ba",",","Dustin","Tran",",","and","Roger","Grosse",".","Flipout",":","Efficient","Pseudo-Independent","Weight","Perturbations","on","Mini-Batches",".","In","_International","Conference","on","Learning","Representations_",",","2018.","https",":","\/\/arxiv.org\/abs\/1803.04386"]
docstr: Construct layer.
  
  Args:
    filters: Integer, the dimensionality of the output space (i.e. the number
      of filters in the convolution).
    kernel_size: An integer or tuple/list of 2 integers, specifying the
      height and width of the 2D convolution window.
      Can be a single integer to specify the same value for
      all spatial dimensions.
    strides: An integer or tuple/list of 2 integers,
      specifying the strides of the convolution along the height and width.
      Can be a single integer to specify the same value for
      all spatial dimensions.
      Specifying any stride value != 1 is incompatible with specifying
      any `dilation_rate` value != 1.
    padding: One of `"valid"` or `"same"` (case-insensitive).
    data_format: A string, one of `channels_last` (default) or
      `channels_first`. The ordering of the dimensions in the inputs.
      `channels_last` corresponds to inputs with shape `(batch, height,
      width, channels)` while `channels_first` corresponds to inputs with
      shape `(batch, channels, height, width)`.
    dilation_rate: An integer or tuple/list of 2 integers, specifying
      the dilation rate to use for dilated convolution.
      Can be a single integer to specify the same value for
      all spatial dimensions.
      Currently, specifying any `dilation_rate` value != 1 is
      incompatible with specifying any stride value != 1.
    ${args}
    seed: Python scalar `int` which initializes the random number
      generator. Default value: `None` (i.e., use global seed).
docstr_tok: ["Construct","layer",".","Args",":","filters",":","Integer",",","the","dimensionality","of","the","output","space","(","i.e",".","the","number","of","filters","in","the","convolution",")",".","kernel_size",":","An","integer","or","tuple\/list","of","2","integers",",","specifying","the","height","and","width","of","the","2D","convolution","window",".","Can","be","a","single","integer","to","specify","the","same","value","for","all","spatial","dimensions",".","strides",":","An","integer","or","tuple\/list","of","2","integers",",","specifying","the","strides","of","the","convolution","along","the","height","and","width",".","Can","be","a","single","integer","to","specify","the","same","value","for","all","spatial","dimensions",".","Specifying","any","stride","value","!","=","1","is","incompatible","with","specifying","any","`","dilation_rate","`","value","!","=","1.","padding",":","One","of","`","``","valid","''","`","or","`","``","same","''","`","(","case-insensitive",")",".","data_format",":","A","string",",","one","of","`","channels_last","`","(","default",")","or","`","channels_first","`",".","The","ordering","of","the","dimensions","in","the","inputs",".","`","channels_last","`","corresponds","to","inputs","with","shape","`","(","batch",",","height",",","width",",","channels",")","`","while","`","channels_first","`","corresponds","to","inputs","with","shape","`","(","batch",",","channels",",","height",",","width",")","`",".","dilation_rate",":","An","integer","or","tuple\/list","of","2","integers",",","specifying","the","dilation","rate","to","use","for","dilated","convolution",".","Can","be","a","single","integer","to","specify","the","same","value","for","all","spatial","dimensions",".","Currently",",","specifying","any","`","dilation_rate","`","value","!","=","1","is","incompatible","with","specifying","any","stride","value","!","=","1",".","$","{","args","}","seed",":","Python","scalar","`","int","`","which","initializes","the","random","number","generator",".","Default","value",":","`","None","`","(","i.e.",",","use","global","seed",")","."]
code: def __init__(
      self,
      filters,
      kernel_size,
      strides=(1, 1),
      padding="valid",
      data_format="channels_last",
      dilation_rate=(1, 1),
      activation=None,
      activity_regularizer=None,
      kernel_posterior_fn=tfp_layers_util.default_mean_field_normal_fn(),
      kernel_posterior_tensor_fn=lambda d: d.sample(),
      kernel_prior_fn=tfp_layers_util.default_multivariate_normal_fn,
      kernel_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(
          q, p
      ),
      bias_posterior_fn=tfp_layers_util.default_mean_field_normal_fn(
          is_singular=True
      ),
      bias_posterior_tensor_fn=lambda d: d.sample(),
      bias_prior_fn=None,
      bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(
          q, p
      ),
      seed=None,
      **kwargs,
  ):
      # pylint: disable=g-doc-args
      """Construct layer.
  
      Args:
        filters: Integer, the dimensionality of the output space (i.e. the number
          of filters in the convolution).
        kernel_size: An integer or tuple/list of 2 integers, specifying the
          height and width of the 2D convolution window.
          Can be a single integer to specify the same value for
          all spatial dimensions.
        strides: An integer or tuple/list of 2 integers,
          specifying the strides of the convolution along the height and width.
          Can be a single integer to specify the same value for
          all spatial dimensions.
          Specifying any stride value != 1 is incompatible with specifying
          any `dilation_rate` value != 1.
        padding: One of `"valid"` or `"same"` (case-insensitive).
        data_format: A string, one of `channels_last` (default) or
          `channels_first`. The ordering of the dimensions in the inputs.
          `channels_last` corresponds to inputs with shape `(batch, height,
          width, channels)` while `channels_first` corresponds to inputs with
          shape `(batch, channels, height, width)`.
        dilation_rate: An integer or tuple/list of 2 integers, specifying
          the dilation rate to use for dilated convolution.
          Can be a single integer to specify the same value for
          all spatial dimensions.
          Currently, specifying any `dilation_rate` value != 1 is
          incompatible with specifying any stride value != 1.
        ${args}
        seed: Python scalar `int` which initializes the random number
          generator. Default value: `None` (i.e., use global seed).
      """
      # pylint: enable=g-doc-args
      super(Conv2DFlipout, self).__init__(
          rank=2,
          filters=filters,
          kernel_size=kernel_size,
          strides=strides,
          padding=padding,
          data_format=data_format,
          dilation_rate=dilation_rate,
          activation=tf_keras.activations.get(activation),
          activity_regularizer=activity_regularizer,
          kernel_posterior_fn=kernel_posterior_fn,
          kernel_posterior_tensor_fn=kernel_posterior_tensor_fn,
          kernel_prior_fn=kernel_prior_fn,
          kernel_divergence_fn=kernel_divergence_fn,
          bias_posterior_fn=bias_posterior_fn,
          bias_posterior_tensor_fn=bias_posterior_tensor_fn,
          bias_prior_fn=bias_prior_fn,
          bias_divergence_fn=bias_divergence_fn,
          seed=seed,
          **kwargs,
      )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python import random
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import docstring_util
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow_probability.python.layers import util
  from tensorflow_probability.python.util.seed_stream import SeedStream
  from tensorflow.python.ops import nn_ops
label_desc: Use image node_id 1 to create a new Conv2DFlipout object from inherited base classes: _ConvFlipout with example: obj = Conv2DFlipout(filters, kernel_size, strides, padding, data_format, dilation_rate, activation, activity_regularizer, kernel_posterior_fn, kernel_posterior_tensor_fn, kernel_prior_fn, kernel_divergence_fn, bias_posterior_fn, bias_posterior_tensor_fn, bias_prior_fn, bias_divergence_fn, seed)