






from typing import List, Optional, Tuple, Union

import torch
from torch import nn
from torch.nn import CrossEntropyLoss

from ... import AutoBackbone
from ...modeling_outputs import SemanticSegmenterOutput
from ...modeling_utils import PreTrainedModel
from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
from ...utils.backbone_utils import BackboneMixin
from .configuration_upernet import UperNetConfig


snake_case     					=		[
    """openmmlab/upernet-convnext-tiny""",
    # See all UperNet models at https://huggingface.co/models?filter=upernet
]

# General docstring
snake_case     					=		"""UperNetConfig"""


class 			SCREAMING_SNAKE_CASE      (      nn.Module       ):
     '''simple docstring'''


     def __init__(					self							:						Optional[Any]       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						Union[int, Tuple[int, int]]       ,			UpperCAmelCase_							:						Union[int, Tuple[int, int], str] = 0       ,			UpperCAmelCase_							:						bool = False       ,			UpperCAmelCase_							:						Union[int, Tuple[int, int]] = 1       ,			):
       super().__init__()
       SCREAMING_SNAKE_CASE							:   str						    =     nn.Convad(
           in_channels=UpperCAmelCase_       ,			out_channels=UpperCAmelCase_       ,			kernel_size=UpperCAmelCase_       ,			padding=UpperCAmelCase_       ,			bias=UpperCAmelCase_       ,			dilation=UpperCAmelCase_       ,			)
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     nn.BatchNormad(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Tuple						    =     nn.ReLU()






     def 					_A							(					self							:						Union[str, Any]       ,			UpperCAmelCase_							:						torch.Tensor   ):
       SCREAMING_SNAKE_CASE							:   Any						    =     self.conv(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Dict						    =     self.batch_norm(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     self.activation(UpperCAmelCase_   )

       return output





class 			SCREAMING_SNAKE_CASE      (      nn.Module       ):
     '''simple docstring'''


     def __init__(					self							:						Union[str, Any]       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						int   ):
       super().__init__()
       SCREAMING_SNAKE_CASE							:   str						    =     [
           nn.AdaptiveAvgPoolad(UpperCAmelCase_   ),
           UperNetConvModule(UpperCAmelCase_       ,			UpperCAmelCase_       ,			kernel_size=1   ),
       ]
       for i, layer in enumerate(self.layers   ):
         self.add_module(str(UpperCAmelCase_   )       ,			UpperCAmelCase_   )






     def 					_A							(					self							:						Any       ,			UpperCAmelCase_							:						torch.Tensor   ):
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     input
       for layer in self.layers:
         SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     layer(UpperCAmelCase_   )
       return hidden_state





class 			SCREAMING_SNAKE_CASE      (      nn.Module       ):
     '''simple docstring'''


     def __init__(					self							:						Dict       ,			UpperCAmelCase_							:						Tuple[int, ...]       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						int       ,			UpperCAmelCase_							:						bool   ):
       super().__init__()
       SCREAMING_SNAKE_CASE							:   Dict						    =     pool_scales
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     align_corners
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     in_channels
       SCREAMING_SNAKE_CASE							:   List[str]						    =     channels
       SCREAMING_SNAKE_CASE							:   str						    =     []
       for i, pool_scale in enumerate(UpperCAmelCase_   ):
         SCREAMING_SNAKE_CASE							:   Optional[int]						    =     UperNetPyramidPoolingBlock(pool_scale=UpperCAmelCase_       ,			in_channels=UpperCAmelCase_       ,			channels=UpperCAmelCase_   )
         self.blocks.append(UpperCAmelCase_   )
         self.add_module(str(UpperCAmelCase_   )       ,			UpperCAmelCase_   )






     def 					_A							(					self							:						Tuple       ,			UpperCAmelCase_							:						torch.Tensor   ):
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     []
       for ppm in self.blocks:
         SCREAMING_SNAKE_CASE							:   Dict						    =     ppm(UpperCAmelCase_   )
         SCREAMING_SNAKE_CASE							:   Tuple						    =     nn.functional.interpolate(
             UpperCAmelCase_       ,			size=x.size()[2:]       ,			mode="bilinear"       ,			align_corners=self.align_corners   )
         ppm_outs.append(UpperCAmelCase_   )
       return ppm_outs





class 			SCREAMING_SNAKE_CASE      (      nn.Module       ):
     '''simple docstring'''


     def __init__(					self							:						str       ,			UpperCAmelCase_							:						Dict       ,			UpperCAmelCase_							:						Optional[Any]   ):
       super().__init__()

       SCREAMING_SNAKE_CASE							:   Tuple						    =     config
       SCREAMING_SNAKE_CASE							:   List[str]						    =     config.pool_scales  # e.g. (1, 2, 3, 6)
       SCREAMING_SNAKE_CASE							:   Dict						    =     in_channels
       SCREAMING_SNAKE_CASE							:   str						    =     config.hidden_size
       SCREAMING_SNAKE_CASE							:   str						    =     False
       SCREAMING_SNAKE_CASE							:   Any						    =     nn.Convad(self.channels       ,			config.num_labels       ,			kernel_size=1   )

       # PSP Module
       SCREAMING_SNAKE_CASE							:   Tuple						    =     UperNetPyramidPoolingModule(
           self.pool_scales       ,			self.in_channels[-1]       ,			self.channels       ,			align_corners=self.align_corners       ,			)
       SCREAMING_SNAKE_CASE							:   Tuple						    =     UperNetConvModule(
           self.in_channels[-1] + len(self.pool_scales   ) * self.channels       ,			self.channels       ,			kernel_size=3       ,			padding=1       ,			)
       # FPN Module
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     nn.ModuleList()
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     nn.ModuleList()
       for in_channels in self.in_channels[:-1]:  # skip the top layer
         SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     UperNetConvModule(UpperCAmelCase_       ,			self.channels       ,			kernel_size=1   )
         SCREAMING_SNAKE_CASE							:   Dict						    =     UperNetConvModule(self.channels       ,			self.channels       ,			kernel_size=3       ,			padding=1   )
         self.lateral_convs.append(UpperCAmelCase_   )
         self.fpn_convs.append(UpperCAmelCase_   )

       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     UperNetConvModule(
           len(self.in_channels   ) * self.channels       ,			self.channels       ,			kernel_size=3       ,			padding=1       ,			)


     def 					_A							(					self							:						Optional[int]   ):
       self.apply(self._init_weights   )


     def 					_A							(					self							:						Tuple       ,			UpperCAmelCase_							:						Union[str, Any]   ):
       if isinstance(UpperCAmelCase_       ,			nn.Convad   ):
         module.weight.data.normal_(mean=0.0       ,			std=self.config.initializer_range   )
         if module.bias is not None:
           module.bias.data.zero_()


     def 					_A							(					self							:						Tuple       ,			UpperCAmelCase_							:						str   ):
       SCREAMING_SNAKE_CASE							:   Any						    =     inputs[-1]
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     [x]
       psp_outs.extend(self.psp_modules(UpperCAmelCase_   )   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     torch.cat(UpperCAmelCase_       ,			dim=1   )
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     self.bottleneck(UpperCAmelCase_   )

       return output






     def 					_A							(					self							:						Dict       ,			UpperCAmelCase_							:						torch.Tensor   ):
       # build laterals
       SCREAMING_SNAKE_CASE							:   Tuple						    =     [lateral_conv(encoder_hidden_states[i]   ) for i, lateral_conv in enumerate(self.lateral_convs   )]

       laterals.append(self.psp_forward(UpperCAmelCase_   )   )

       # build top-down path
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     len(UpperCAmelCase_   )
       for i in range(used_backbone_levels - 1       ,			0       ,			-1   ):
         SCREAMING_SNAKE_CASE							:   Optional[int]						    =     laterals[i - 1].shape[2:]
         SCREAMING_SNAKE_CASE							:   List[str]						    =     laterals[i - 1] + nn.functional.interpolate(
             laterals[i]       ,			size=UpperCAmelCase_       ,			mode="bilinear"       ,			align_corners=self.align_corners   )

       # build outputs
       SCREAMING_SNAKE_CASE							:   Any						    =     [self.fpn_convs[i](laterals[i]   ) for i in range(used_backbone_levels - 1   )]
       # append psp feature
       fpn_outs.append(laterals[-1]   )

       for i in range(used_backbone_levels - 1       ,			0       ,			-1   ):
         SCREAMING_SNAKE_CASE							:   List[Any]						    =     nn.functional.interpolate(
             fpn_outs[i]       ,			size=fpn_outs[0].shape[2:]       ,			mode="bilinear"       ,			align_corners=self.align_corners   )
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     torch.cat(UpperCAmelCase_       ,			dim=1   )
       SCREAMING_SNAKE_CASE							:   Tuple						    =     self.fpn_bottleneck(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     self.classifier(UpperCAmelCase_   )

       return output





class 			SCREAMING_SNAKE_CASE      (      nn.Module       ):
     '''simple docstring'''


     def __init__(					self							:						List[str]       ,			UpperCAmelCase_							:						str       ,			UpperCAmelCase_							:						int = 2       ,			UpperCAmelCase_							:						int = 3       ,			UpperCAmelCase_							:						Union[int, Tuple[int, int]] = 1   ):
       super().__init__()

       SCREAMING_SNAKE_CASE							:   int						    =     config
       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     config.auxiliary_in_channels
       SCREAMING_SNAKE_CASE							:   List[str]						    =     config.auxiliary_channels
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     config.auxiliary_num_convs
       SCREAMING_SNAKE_CASE							:   Tuple						    =     config.auxiliary_concat_input
       SCREAMING_SNAKE_CASE							:   Optional[int]						    =     in_index

       SCREAMING_SNAKE_CASE							:   List[Any]						    =     (kernel_size // 2) * dilation
       SCREAMING_SNAKE_CASE							:   int						    =     []
       convs.append(
           UperNetConvModule(
               self.in_channels       ,			self.channels       ,			kernel_size=UpperCAmelCase_       ,			padding=UpperCAmelCase_       ,			dilation=UpperCAmelCase_   )   )
       for i in range(self.num_convs - 1   ):
         convs.append(
             UperNetConvModule(
                 self.channels       ,			self.channels       ,			kernel_size=UpperCAmelCase_       ,			padding=UpperCAmelCase_       ,			dilation=UpperCAmelCase_   )   )
       if self.num_convs == 0:
         SCREAMING_SNAKE_CASE							:   Optional[int]						    =     nn.Identity()
       else:
         SCREAMING_SNAKE_CASE							:   List[str]						    =     nn.Sequential(*UpperCAmelCase_   )
       if self.concat_input:
         SCREAMING_SNAKE_CASE							:   Dict						    =     UperNetConvModule(
             self.in_channels + self.channels       ,			self.channels       ,			kernel_size=UpperCAmelCase_       ,			padding=kernel_size // 2   )

       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     nn.Convad(self.channels       ,			config.num_labels       ,			kernel_size=1   )


     def 					_A							(					self							:						Optional[int]   ):
       self.apply(self._init_weights   )


     def 					_A							(					self							:						int       ,			UpperCAmelCase_							:						Union[str, Any]   ):
       if isinstance(UpperCAmelCase_       ,			nn.Convad   ):
         module.weight.data.normal_(mean=0.0       ,			std=self.config.initializer_range   )
         if module.bias is not None:
           module.bias.data.zero_()






     def 					_A							(					self							:						Tuple       ,			UpperCAmelCase_							:						torch.Tensor   ):
       # just take the relevant feature maps
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     encoder_hidden_states[self.in_index]
       SCREAMING_SNAKE_CASE							:   Any						    =     self.convs(UpperCAmelCase_   )
       if self.concat_input:
         SCREAMING_SNAKE_CASE							:   str						    =     self.conv_cat(torch.cat([hidden_states, output]       ,			dim=1   )   )
       SCREAMING_SNAKE_CASE							:   int						    =     self.classifier(UpperCAmelCase_   )
       return output





class 			SCREAMING_SNAKE_CASE      (      lowerCAmelCase       ):
     '''simple docstring'''


     UpperCamelCase_				:		Tuple								=						UperNetConfig
     UpperCamelCase_				:		List[str]								=						'''pixel_values'''
     UpperCamelCase_				:		List[str]								=						True


     def 					_A							(					self							:						Tuple       ,			UpperCAmelCase_							:						Tuple   ):
       if isinstance(UpperCAmelCase_       ,			UpperCAmelCase_   ):
         module.backbone.init_weights()
         module.decode_head.init_weights()
         module.auxiliary_head.init_weights()


     def 					_A							(					self							:						Tuple   ):
       self.backbone.init_weights()
       self.decode_head.init_weights()
       self.auxiliary_head.init_weights()






     def 					_A							(					self							:						Dict       ,			UpperCAmelCase_							:						List[str]       ,			UpperCAmelCase_							:						Dict=False   ):
       if isinstance(UpperCAmelCase_       ,			UpperCAmelCase_   ):
         SCREAMING_SNAKE_CASE							:   List[Any]						    =     value





snake_case     					=		r"""
    Parameters:
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.
        config ([`UperNetConfig`]): 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.
"""

snake_case     					=		r"""
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using
            [`AutoImageProcessor`]. See [`SegformerImageProcessor.__call__`] for details.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers in case the backbone has them. See
            `attentions` under returned tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers of the backbone. 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(
    '''UperNet framework leveraging any vision backbone e.g. for ADE20k, CityScapes.'''   ,		lowerCAmelCase   ,		)
class 			SCREAMING_SNAKE_CASE      (      lowerCAmelCase       ):
     '''simple docstring'''


     def __init__(					self							:						Any       ,			UpperCAmelCase_							:						Any   ):
       super().__init__(UpperCAmelCase_   )

       SCREAMING_SNAKE_CASE							:   List[str]						    =     AutoBackbone.from_config(config.backbone_config   )

       # Semantic segmentation head(s)
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     UperNetHead(UpperCAmelCase_       ,			in_channels=self.backbone.channels   )
       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     UperNetFCNHead(UpperCAmelCase_   ) if config.use_auxiliary_head else None

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






     @add_start_docstrings_to_model_forward(UPERNET_INPUTS_DOCSTRING.format("batch_size, sequence_length"   )   )
     @replace_return_docstrings(output_type=UpperCAmelCase_       ,			config_class=_CONFIG_FOR_DOC   )
     def 					_A							(					self							:						Union[str, Any]       ,			UpperCAmelCase_							:						Optional[torch.Tensor] = None       ,			UpperCAmelCase_							:						Optional[bool] = None       ,			UpperCAmelCase_							:						Optional[bool] = None       ,			UpperCAmelCase_							:						Optional[torch.Tensor] = None       ,			UpperCAmelCase_							:						Optional[bool] = None       ,			):
       SCREAMING_SNAKE_CASE							:   int						    =     return_dict if return_dict is not None else self.config.use_return_dict
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     (
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     output_attentions if output_attentions is not None else self.config.output_attentions

       SCREAMING_SNAKE_CASE							:   Tuple						    =     self.backbone.forward_with_filtered_kwargs(
           UpperCAmelCase_       ,			output_hidden_states=UpperCAmelCase_       ,			output_attentions=UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   List[str]						    =     outputs.feature_maps

       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     self.decode_head(UpperCAmelCase_   )
       SCREAMING_SNAKE_CASE							:   str						    =     nn.functional.interpolate(UpperCAmelCase_       ,			size=pixel_values.shape[2:]       ,			mode="bilinear"       ,			align_corners=UpperCAmelCase_   )

       SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     None
       if self.auxiliary_head is not None:
         SCREAMING_SNAKE_CASE							:   Dict						    =     self.auxiliary_head(UpperCAmelCase_   )
         SCREAMING_SNAKE_CASE							:   int						    =     nn.functional.interpolate(
             UpperCAmelCase_       ,			size=pixel_values.shape[2:]       ,			mode="bilinear"       ,			align_corners=UpperCAmelCase_   )

       SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     None
       if labels is not None:
         if self.config.num_labels == 1:
           raise ValueError("The number of labels should be greater than one"   )
         else:
           # compute weighted loss
           SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     CrossEntropyLoss(ignore_index=self.config.loss_ignore_index   )
           SCREAMING_SNAKE_CASE							:   Dict						    =     loss_fct(UpperCAmelCase_       ,			UpperCAmelCase_   )
           SCREAMING_SNAKE_CASE							:   int						    =     loss_fct(UpperCAmelCase_       ,			UpperCAmelCase_   )
           SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     main_loss + self.config.auxiliary_loss_weight * auxiliary_loss

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

       return SemanticSegmenterOutput(
           loss=UpperCAmelCase_       ,			logits=UpperCAmelCase_       ,			hidden_states=outputs.hidden_states       ,			attentions=outputs.attentions       ,			)












'''simple docstring'''







def 						_A      ( ):






   '''simple docstring'''







   A__       =     [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

   A__       =     6
   A__       =     1
   A__       =     1901

   A__       =     0

   while year < 2001:
      day += 7

      if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
         if day > days_per_month[month - 1] and month != 2:
            month += 1
            A__       =     day - days_per_month[month - 2]
         elif day > 29 and month == 2:
            month += 1
            A__       =     day - 29
      else:
         if day > days_per_month[month - 1]:
            month += 1
            A__       =     day - days_per_month[month - 2]

      if month > 12:
         year += 1
         A__       =     1

      if year < 2001 and day == 1:
         sundays += 1
   return sundays


if __name__ == "__main__":
    print(solution())


