





from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import (
    BackboneOutput,
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import (
    add_code_sample_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    logging,
    replace_return_docstrings,
)
from ...utils.backbone_utils import BackboneMixin
from .configuration_resnet import ResNetConfig


lowercase_          =		logging.get_logger(__name__)

# General docstring
lowercase_          =		'''ResNetConfig'''

# Base docstring
lowercase_          =		'''microsoft/resnet-50'''
lowercase_          =		[1, 2_048, 7, 7]

# Image classification docstring
lowercase_          =		'''microsoft/resnet-50'''
lowercase_          =		'''tiger cat'''

lowercase_          =		[
    '''microsoft/resnet-50''',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]
class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    Union[str, Any]      ,					a      :    List[Any]      ,					a      :    int      ,					a      :    List[Any] = 3      ,					a      :    Union[str, Any] = 1      ,					a      :    str = "relu"	)->       str:





     """simple docstring"""







     super().__init__()
     lowercase__           =  nn.Convad(
         _SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					kernel_size=_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE      ,					padding=kernel_size // 2      ,					bias=_SCREAMING_SNAKE_CASE	)
     lowercase__           =  nn.BatchNormad(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  ACTaFN[activation] if activation is not None else nn.Identity()


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    List[str]	)->       Tensor:





     """simple docstring"""







     lowercase__           =  self.convolution(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.normalization(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.activation(_SCREAMING_SNAKE_CASE	)
     return hidden_state






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    List[Any]      ,					a      :    int	)->       Optional[Any]:





     """simple docstring"""







     super().__init__()
     lowercase__           =  ResNetConvLayer(
         config.num_channels      ,					config.embedding_size      ,					kernel_size=7      ,					stride=2      ,					activation=config.hidden_act	)
     lowercase__           =  nn.MaxPoolad(kernel_size=3      ,					stride=2      ,					padding=1	)
     lowercase__           =  config.num_channels


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Union[str, Any]	)->       Tensor:





     """simple docstring"""







     lowercase__           =  pixel_values.shape[1]
     if num_channels != self.num_channels:
       raise ValueError(
           'Make sure that the channel dimension of the pixel values match with the one set in the configuration.'	)
     lowercase__           =  self.embedder(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.pooler(_SCREAMING_SNAKE_CASE	)
     return embedding






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    Optional[Any]      ,					a      :    Optional[int]      ,					a      :    Tuple      ,					a      :    int = 2	)->       List[Any]:





     """simple docstring"""







     super().__init__()
     lowercase__           =  nn.Convad(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					kernel_size=1      ,					stride=_SCREAMING_SNAKE_CASE      ,					bias=_SCREAMING_SNAKE_CASE	)
     lowercase__           =  nn.BatchNormad(_SCREAMING_SNAKE_CASE	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    int	)->       Tensor:





     """simple docstring"""







     lowercase__           =  self.convolution(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.normalization(_SCREAMING_SNAKE_CASE	)
     return hidden_state






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    Optional[int]      ,					a      :    List[Any]      ,					a      :    Optional[Any]      ,					a      :    List[str] = 1      ,					a      :    str = "relu"	)->       Tuple:





     """simple docstring"""







     super().__init__()
     lowercase__           =  in_channels != out_channels or stride != 1
     lowercase__           =  (
         ResNetShortCut(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE	) if should_apply_shortcut else nn.Identity()
     )
     lowercase__           =  nn.Sequential(
         ResNetConvLayer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE	)      ,					ResNetConvLayer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					activation=_SCREAMING_SNAKE_CASE	)      ,					)
     lowercase__           =  ACTaFN[activation]


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    Any	)->       int:





     """simple docstring"""







     lowercase__           =  hidden_state
     lowercase__           =  self.layer(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.shortcut(_SCREAMING_SNAKE_CASE	)
     hidden_state += residual
     lowercase__           =  self.activation(_SCREAMING_SNAKE_CASE	)
     return hidden_state






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    Optional[int]      ,					a      :    Dict      ,					a      :    Union[str, Any]      ,					a      :    Optional[Any] = 1      ,					a      :    Dict = "relu"      ,					a      :    Optional[Any] = 4	)->       Dict:





     """simple docstring"""







     super().__init__()
     lowercase__           =  in_channels != out_channels or stride != 1
     lowercase__           =  out_channels // reduction
     lowercase__           =  (
         ResNetShortCut(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE	) if should_apply_shortcut else nn.Identity()
     )
     lowercase__           =  nn.Sequential(
         ResNetConvLayer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					kernel_size=1	)      ,					ResNetConvLayer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE	)      ,					ResNetConvLayer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					kernel_size=1      ,					activation=_SCREAMING_SNAKE_CASE	)      ,					)
     lowercase__           =  ACTaFN[activation]


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    Optional[int]	)->       int:





     """simple docstring"""







     lowercase__           =  hidden_state
     lowercase__           =  self.layer(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  self.shortcut(_SCREAMING_SNAKE_CASE	)
     hidden_state += residual
     lowercase__           =  self.activation(_SCREAMING_SNAKE_CASE	)
     return hidden_state






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    Any      ,					a      :    int      ,					a      :    Optional[int]      ,					a      :    List[Any]      ,					a      :    Dict = 2      ,					a      :    Tuple = 2      ,					)->       Tuple:





     """simple docstring"""







     super().__init__()

     lowercase__           =  ResNetBottleNeckLayer if config.layer_type == "bottleneck" else ResNetBasicLayer

     lowercase__           =  nn.Sequential(
         # downsampling is done in the first layer with stride of 2
         layer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					stride=_SCREAMING_SNAKE_CASE      ,					activation=config.hidden_act	)      ,					*[layer(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					activation=config.hidden_act	) for _ in range(depth - 1	)]      ,					)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Any	)->       Tensor:





     """simple docstring"""







     lowercase__           =  input
     for layer in self.layers:
       lowercase__           =  layer(_SCREAMING_SNAKE_CASE	)
     return hidden_state






class     SCREAMING_SNAKE_CASE       (nn.Module				):


   def __init__(   self      :    str      ,					a      :    List[Any]	)->       Dict:





     """simple docstring"""







     super().__init__()
     lowercase__           =  nn.ModuleList([]	)
     # based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
     self.stages.append(
         ResNetStage(
             _SCREAMING_SNAKE_CASE      ,					config.embedding_size      ,					config.hidden_sizes[0]      ,					stride=2 if config.downsample_in_first_stage else 1      ,					depth=config.depths[0]      ,					)	)
     lowercase__           =  zip(config.hidden_sizes      ,					config.hidden_sizes[1:]	)
     for (in_channels, out_channels), depth in zip(_SCREAMING_SNAKE_CASE      ,					config.depths[1:]	):
       self.stages.append(ResNetStage(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE      ,					depth=_SCREAMING_SNAKE_CASE	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict      ,					a      :    Tuple      ,					a      :    int = False      ,					a      :    Tuple = True	)->       BaseModelOutputWithNoAttention:





     """simple docstring"""







     lowercase__           =  () if output_hidden_states else None

     for stage_module in self.stages:
       if output_hidden_states:
         lowercase__           =  hidden_states + (hidden_state,)

       lowercase__           =  stage_module(_SCREAMING_SNAKE_CASE	)

     if output_hidden_states:
       lowercase__           =  hidden_states + (hidden_state,)

     if not return_dict:
       return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

     return BaseModelOutputWithNoAttention(
         last_hidden_state=_SCREAMING_SNAKE_CASE      ,					hidden_states=_SCREAMING_SNAKE_CASE      ,					)






class     SCREAMING_SNAKE_CASE       (SCREAMING_SNAKE_CASE__				):
   _UpperCamelCase   :		Tuple			 =	ResNetConfig
   _UpperCamelCase   :		List[Any]			 =	'resnet'
   _UpperCamelCase   :		Dict			 =	'pixel_values'
   _UpperCamelCase   :		Optional[int]			 =	True


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    Optional[int]	)->       Optional[int]:





     """simple docstring"""







     if isinstance(_SCREAMING_SNAKE_CASE      ,					nn.Convad	):
       nn.init.kaiming_normal_(module.weight      ,					mode='fan_out'      ,					nonlinearity='relu'	)
     elif isinstance(_SCREAMING_SNAKE_CASE      ,					(nn.BatchNormad, nn.GroupNorm)	):
       nn.init.constant_(module.weight      ,					1	)
       nn.init.constant_(module.bias      ,					0	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]      ,					a      :    Any      ,					a      :    Tuple=False	)->       Optional[int]:





     """simple docstring"""







     if isinstance(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE	):
       lowercase__           =  value






lowercase_          =		r'''
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
'''

lowercase_          =		r'''
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''
@add_start_docstrings(
    'The bare ResNet model outputting raw features without any specific head on top.'      ,     SCREAMING_SNAKE_CASE__      ,     )
class     SCREAMING_SNAKE_CASE       (SCREAMING_SNAKE_CASE__				):


   def __init__(   self      :    List[str]      ,					a      :    Optional[Any]	)->       Optional[Any]:





     """simple docstring"""







     super().__init__(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  config
     lowercase__           =  ResNetEmbeddings(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  ResNetEncoder(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  nn.AdaptiveAvgPoolad((1, 1)	)
     # Initialize weights and apply final processing
     self.post_init()


   @add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE	)
   @add_code_sample_docstrings(
       checkpoint=_CHECKPOINT_FOR_DOC      ,					output_type=_SCREAMING_SNAKE_CASE      ,					config_class=_CONFIG_FOR_DOC      ,					modality='vision'      ,					expected_output=_EXPECTED_OUTPUT_SHAPE      ,					)
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    Tuple      ,					a      :    Any = None      ,					a      :    List[str] = None	)->       BaseModelOutputWithPoolingAndNoAttention:





     """simple docstring"""







     lowercase__           =  (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     lowercase__           =  return_dict if return_dict is not None else self.config.use_return_dict

     lowercase__           =  self.embedder(_SCREAMING_SNAKE_CASE	)

     lowercase__           =  self.encoder(
         _SCREAMING_SNAKE_CASE      ,					output_hidden_states=_SCREAMING_SNAKE_CASE      ,					return_dict=_SCREAMING_SNAKE_CASE	)

     lowercase__           =  encoder_outputs[0]

     lowercase__           =  self.pooler(_SCREAMING_SNAKE_CASE	)

     if not return_dict:
       return (last_hidden_state, pooled_output) + encoder_outputs[1:]

     return BaseModelOutputWithPoolingAndNoAttention(
         last_hidden_state=_SCREAMING_SNAKE_CASE      ,					pooler_output=_SCREAMING_SNAKE_CASE      ,					hidden_states=encoder_outputs.hidden_states      ,					)






@add_start_docstrings(
    '\n    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '      ,     SCREAMING_SNAKE_CASE__      ,     )
class     SCREAMING_SNAKE_CASE       (SCREAMING_SNAKE_CASE__				):


   def __init__(   self      :    Union[str, Any]      ,					a      :    List[str]	)->       Dict:





     """simple docstring"""







     super().__init__(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  config.num_labels
     lowercase__           =  ResNetModel(_SCREAMING_SNAKE_CASE	)
     # classification head
     lowercase__           =  nn.Sequential(
         nn.Flatten()      ,					nn.Linear(config.hidden_sizes[-1]      ,					config.num_labels	) if config.num_labels > 0 else nn.Identity()      ,					)
     # initialize weights and apply final processing
     self.post_init()


   @add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE	)
   @add_code_sample_docstrings(
       checkpoint=_IMAGE_CLASS_CHECKPOINT      ,					output_type=_SCREAMING_SNAKE_CASE      ,					config_class=_CONFIG_FOR_DOC      ,					expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,					)
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Union[str, Any] = None      ,					a      :    int = None      ,					a      :    Dict = None      ,					a      :    List[str] = None      ,					)->       ImageClassifierOutputWithNoAttention:





     """simple docstring"""







     lowercase__           =  return_dict if return_dict is not None else self.config.use_return_dict

     lowercase__           =  self.resnet(_SCREAMING_SNAKE_CASE      ,					output_hidden_states=_SCREAMING_SNAKE_CASE      ,					return_dict=_SCREAMING_SNAKE_CASE	)

     lowercase__           =  outputs.pooler_output if return_dict else outputs[1]

     lowercase__           =  self.classifier(_SCREAMING_SNAKE_CASE	)

     lowercase__           =  None

     if labels is not None:
       if self.config.problem_type is None:
         if self.num_labels == 1:
           lowercase__           =  "regression"
         elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
           lowercase__           =  "single_label_classification"
         else:
           lowercase__           =  "multi_label_classification"
       if self.config.problem_type == "regression":
         lowercase__           =  MSELoss()
         if self.num_labels == 1:
           lowercase__           =  loss_fct(logits.squeeze()      ,					labels.squeeze()	)
         else:
           lowercase__           =  loss_fct(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE	)
       elif self.config.problem_type == "single_label_classification":
         lowercase__           =  CrossEntropyLoss()
         lowercase__           =  loss_fct(logits.view(-1      ,					self.num_labels	)      ,					labels.view(-1	)	)
       elif self.config.problem_type == "multi_label_classification":
         lowercase__           =  BCEWithLogitsLoss()
         lowercase__           =  loss_fct(_SCREAMING_SNAKE_CASE      ,					_SCREAMING_SNAKE_CASE	)

     if not return_dict:
       lowercase__           =  (logits,) + outputs[2:]
       return (loss,) + output if loss is not None else output

     return ImageClassifierOutputWithNoAttention(loss=_SCREAMING_SNAKE_CASE      ,					logits=_SCREAMING_SNAKE_CASE      ,					hidden_states=outputs.hidden_states	)






@add_start_docstrings(
    '\n    ResNet backbone, to be used with frameworks like DETR and MaskFormer.\n    '      ,     SCREAMING_SNAKE_CASE__      ,     )
class     SCREAMING_SNAKE_CASE       (SCREAMING_SNAKE_CASE__      ,     SCREAMING_SNAKE_CASE__				):


   def __init__(   self      :    Dict      ,					a      :    List[str]	)->       int:





     """simple docstring"""







     super().__init__(_SCREAMING_SNAKE_CASE	)
     super()._init_backbone(_SCREAMING_SNAKE_CASE	)

     lowercase__           =  [config.embedding_size] + config.hidden_sizes
     lowercase__           =  ResNetEmbeddings(_SCREAMING_SNAKE_CASE	)
     lowercase__           =  ResNetEncoder(_SCREAMING_SNAKE_CASE	)

     # initialize weights and apply final processing
     self.post_init()


   @add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE	)
   @replace_return_docstrings(output_type=_SCREAMING_SNAKE_CASE      ,					config_class=_CONFIG_FOR_DOC	)
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Optional[Any]      ,					a      :    Any = None      ,					a      :    List[str] = None	)->       BackboneOutput:





     """simple docstring"""







     lowercase__           =  return_dict if return_dict is not None else self.config.use_return_dict
     lowercase__           =  (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )

     lowercase__           =  self.embedder(_SCREAMING_SNAKE_CASE	)

     lowercase__           =  self.encoder(_SCREAMING_SNAKE_CASE      ,					output_hidden_states=_SCREAMING_SNAKE_CASE      ,					return_dict=_SCREAMING_SNAKE_CASE	)

     lowercase__           =  outputs.hidden_states

     lowercase__           =  ()
     for idx, stage in enumerate(self.stage_names	):
       if stage in self.out_features:
         feature_maps += (hidden_states[idx],)

     if not return_dict:
       lowercase__           =  (feature_maps,)
       if output_hidden_states:
         output += (outputs.hidden_states,)
       return output

     return BackboneOutput(
         feature_maps=_SCREAMING_SNAKE_CASE      ,					hidden_states=outputs.hidden_states if output_hidden_states else None      ,					attentions=_SCREAMING_SNAKE_CASE      ,					)









import sys

lowercase_          =		(
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE = N		)    ->       int:
  lowercase__           =  -sys.maxsize - 1
  for i in range(len(_SCREAMING_SNAKE_CASE		) - 12		):
    lowercase__           =  1
    for j in range(13		):
      product *= int(n[i + j]		)
    if product > largest_product:
      lowercase__           =  product
  return largest_product


if __name__ == "__main__":
      print(f'''{solution() = }''')


