class_docstr: ResNet V2 block with optional bottleneck.
class_docstr_tok: ["ResNet","V2","block","with","optional","bottleneck","."]
code: def __init__(
      self,
      channels: int,
      stride: Union[int, Sequence[int]],
      use_projection: bool,
      bn_config: Mapping[str, FloatStrOrBool],
      bottleneck: bool,
      name: Optional[str] = None,
  ):
      super().__init__(name=name)
      self.use_projection = use_projection
  
      bn_config = dict(bn_config)
      bn_config.setdefault("create_scale", True)
      bn_config.setdefault("create_offset", True)
  
      if self.use_projection:
          self.proj_conv = hk.Conv2D(
              output_channels=channels,
              kernel_shape=1,
              stride=stride,
              with_bias=False,
              padding="SAME",
              name="shortcut_conv",
          )
  
      channel_div = 4 if bottleneck else 1
      conv_0 = hk.Conv2D(
          output_channels=channels // channel_div,
          kernel_shape=1 if bottleneck else 3,
          stride=1 if bottleneck else stride,
          with_bias=False,
          padding="SAME",
          name="conv_0",
      )
  
      bn_0 = hk.BatchNorm(name="batchnorm_0", **bn_config)
  
      conv_1 = hk.Conv2D(
          output_channels=channels // channel_div,
          kernel_shape=3,
          stride=stride if bottleneck else 1,
          with_bias=False,
          padding="SAME",
          name="conv_1",
      )
  
      bn_1 = hk.BatchNorm(name="batchnorm_1", **bn_config)
      layers = ((conv_0, bn_0), (conv_1, bn_1))
  
      if bottleneck:
          conv_2 = hk.Conv2D(
              output_channels=channels,
              kernel_shape=1,
              stride=1,
              with_bias=False,
              padding="SAME",
              name="conv_2",
          )
  
          # NOTE: Some implementations of ResNet50 v2 suggest initializing
          # gamma/scale here to zeros.
          bn_2 = hk.BatchNorm(name="batchnorm_2", **bn_config)
          layers = layers + ((conv_2, bn_2),)
  
      self.layers = layers
  
imports: from collections.abc import Mapping, Sequence
  from typing import Any, Optional, Union
  from haiku._src import basic
  from haiku._src import batch_norm
  from haiku._src import conv
  from haiku._src import module
  from haiku._src import pool
  import jax
  import jax.numpy
label_desc: Use image node_id 1 to create a new BlockV2 object from inherited base classes: hk with example: obj = BlockV2(channels, stride, use_projection, bn_config, bottleneck, name)