class_docstr: ResNet model.
class_docstr_tok: ["ResNet","model","."]
docstr: Constructs a ResNet model.
  
  Args:
    blocks_per_group: A sequence of length 4 that indicates the number of
      blocks created in each group.
    num_classes: The number of classes to classify the inputs into.
    bn_config: A dictionary of two elements, ``decay_rate`` and ``eps`` to be
      passed on to the :class:`~haiku.BatchNorm` layers. By default the
      ``decay_rate`` is ``0.9`` and ``eps`` is ``1e-5``.
    resnet_v2: Whether to use the v1 or v2 ResNet implementation. Defaults to
      ``False``.
    bottleneck: Whether the block should bottleneck or not. Defaults to
      ``True``.
    channels_per_group: A sequence of length 4 that indicates the number
      of channels used for each block in each group.
    use_projection: A sequence of length 4 that indicates whether each
      residual block should use projection.
    logits_config: A dictionary of keyword arguments for the logits layer.
    name: Name of the module.
    initial_conv_config: Keyword arguments passed to the constructor of the
      initial :class:`~haiku.Conv2D` module.
    strides: A sequence of length 4 that indicates the size of stride
      of convolutions for each block in each group.
docstr_tok: ["Constructs","a","ResNet","model",".","Args",":","blocks_per_group",":","A","sequence","of","length","4","that","indicates","the","number","of","blocks","created","in","each","group",".","num_classes",":","The","number","of","classes","to","classify","the","inputs","into",".","bn_config",":","A","dictionary","of","two","elements",",","``","decay_rate","``","and","``","eps","``","to","be","passed","on","to","the",":","class",":","`","~haiku.BatchNorm","`","layers",".","By","default","the","``","decay_rate","``","is","``","0.9","``","and","``","eps","``","is","``","1e-5","``",".","resnet_v2",":","Whether","to","use","the","v1","or","v2","ResNet","implementation",".","Defaults","to","``","False","``",".","bottleneck",":","Whether","the","block","should","bottleneck","or","not",".","Defaults","to","``","True","``",".","channels_per_group",":","A","sequence","of","length","4","that","indicates","the","number","of","channels","used","for","each","block","in","each","group",".","use_projection",":","A","sequence","of","length","4","that","indicates","whether","each","residual","block","should","use","projection",".","logits_config",":","A","dictionary","of","keyword","arguments","for","the","logits","layer",".","name",":","Name","of","the","module",".","initial_conv_config",":","Keyword","arguments","passed","to","the","constructor","of","the","initial",":","class",":","`","~haiku.Conv2D","`","module",".","strides",":","A","sequence","of","length","4","that","indicates","the","size","of","stride","of","convolutions","for","each","block","in","each","group","."]
code: def __init__(
      self,
      blocks_per_group: Sequence[int],
      num_classes: int,
      bn_config: Optional[Mapping[str, FloatStrOrBool]] = None,
      resnet_v2: bool = False,
      bottleneck: bool = True,
      channels_per_group: Sequence[int] = (256, 512, 1024, 2048),
      use_projection: Sequence[bool] = (True, True, True, True),
      logits_config: Optional[Mapping[str, Any]] = None,
      name: Optional[str] = None,
      initial_conv_config: Optional[
          Mapping[str, FloatStrOrBool]
      ] = None,
      strides: Sequence[int] = (1, 2, 2, 2),
  ):
      """Constructs a ResNet model.
  
      Args:
        blocks_per_group: A sequence of length 4 that indicates the number of
          blocks created in each group.
        num_classes: The number of classes to classify the inputs into.
        bn_config: A dictionary of two elements, ``decay_rate`` and ``eps`` to be
          passed on to the :class:`~haiku.BatchNorm` layers. By default the
          ``decay_rate`` is ``0.9`` and ``eps`` is ``1e-5``.
        resnet_v2: Whether to use the v1 or v2 ResNet implementation. Defaults to
          ``False``.
        bottleneck: Whether the block should bottleneck or not. Defaults to
          ``True``.
        channels_per_group: A sequence of length 4 that indicates the number
          of channels used for each block in each group.
        use_projection: A sequence of length 4 that indicates whether each
          residual block should use projection.
        logits_config: A dictionary of keyword arguments for the logits layer.
        name: Name of the module.
        initial_conv_config: Keyword arguments passed to the constructor of the
          initial :class:`~haiku.Conv2D` module.
        strides: A sequence of length 4 that indicates the size of stride
          of convolutions for each block in each group.
      """
      super().__init__(name=name)
      self.resnet_v2 = resnet_v2
  
      bn_config = dict(bn_config or {})
      bn_config.setdefault("decay_rate", 0.9)
      bn_config.setdefault("eps", 1e-5)
      bn_config.setdefault("create_scale", True)
      bn_config.setdefault("create_offset", True)
  
      logits_config = dict(logits_config or {})
      logits_config.setdefault("w_init", jnp.zeros)
      logits_config.setdefault("name", "logits")
  
      # Number of blocks in each group for ResNet.
      check_length(4, blocks_per_group, "blocks_per_group")
      check_length(4, channels_per_group, "channels_per_group")
      check_length(4, strides, "strides")
  
      initial_conv_config = dict(initial_conv_config or {})
      initial_conv_config.setdefault("output_channels", 64)
      initial_conv_config.setdefault("kernel_shape", 7)
      initial_conv_config.setdefault("stride", 2)
      initial_conv_config.setdefault("with_bias", False)
      initial_conv_config.setdefault("padding", "SAME")
      initial_conv_config.setdefault("name", "initial_conv")
  
      self.initial_conv = hk.Conv2D(**initial_conv_config)
  
      if not self.resnet_v2:
          self.initial_batchnorm = hk.BatchNorm(
              name="initial_batchnorm", **bn_config
          )
  
      self.block_groups = []
      for i, stride in enumerate(strides):
          self.block_groups.append(
              BlockGroup(
                  channels=channels_per_group[i],
                  num_blocks=blocks_per_group[i],
                  stride=stride,
                  bn_config=bn_config,
                  resnet_v2=resnet_v2,
                  bottleneck=bottleneck,
                  use_projection=use_projection[i],
                  name="block_group_%d" % (i),
              )
          )
  
      if self.resnet_v2:
          self.final_batchnorm = hk.BatchNorm(
              name="final_batchnorm", **bn_config
          )
  
      self.logits = hk.Linear(num_classes, **logits_config)
  
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 ResNet object from inherited base classes: hk with example: obj = ResNet(blocks_per_group, num_classes, bn_config, resnet_v2, bottleneck, channels_per_group, use_projection, logits_config, name, initial_conv_config, strides)