


'''simple docstring'''







import numpy as np
from PIL import Image






def       lowercase					(_A ,    _A ,    _A       ):







       """simple docstring"""







       _lowerCAmelCase     :				Any       =							np.array(_A       )
       if arr.shape[0] != arr.shape[1]:
              raise ValueError('The input array is not a square matrix'       )
       _lowerCAmelCase     :				Any       =							0
       _lowerCAmelCase     :				Dict       =							0
       _lowerCAmelCase     :				List[Any]       =							0
       _lowerCAmelCase     :				List[str]       =							0

       # compute the shape of the output matrix
       _lowerCAmelCase     :				Optional[Any]       =							(arr.shape[0] - size) // stride + 1
       # initialize the output matrix with zeros of shape maxpool_shape
       _lowerCAmelCase     :				Optional[Any]       =							np.zeros((maxpool_shape, maxpool_shape)       )

       while i < arr.shape[0]:
              if i + size > arr.shape[0]:
                     # if the end of the matrix is reached, break
                     break
              while j < arr.shape[1]:
                     # if the end of the matrix is reached, break
                     if j + size > arr.shape[1]:
                            break
                     # compute the maximum of the pooling matrix
                     _lowerCAmelCase     :				Any       =							np.max(arr[i : i + size, j : j + size]       )
                     # shift the pooling matrix by stride of column pixels
                     j += stride
                     mat_j += 1

              # shift the pooling matrix by stride of row pixels
              i += stride
              mat_i += 1

              # reset the column index to 0
              _lowerCAmelCase     :				Union[str, Any]       =							0
              _lowerCAmelCase     :				Optional[int]       =							0

       return updated_arr






def       lowercase					(_A ,    _A ,    _A       ):







       """simple docstring"""







       _lowerCAmelCase     :				str       =							np.array(_A       )
       if arr.shape[0] != arr.shape[1]:
              raise ValueError('The input array is not a square matrix'       )
       _lowerCAmelCase     :				Any       =							0
       _lowerCAmelCase     :				Dict       =							0
       _lowerCAmelCase     :				Union[str, Any]       =							0
       _lowerCAmelCase     :				Optional[int]       =							0

       # compute the shape of the output matrix
       _lowerCAmelCase     :				Dict       =							(arr.shape[0] - size) // stride + 1
       # initialize the output matrix with zeros of shape avgpool_shape
       _lowerCAmelCase     :				List[Any]       =							np.zeros((avgpool_shape, avgpool_shape)       )

       while i < arr.shape[0]:
              # if the end of the matrix is reached, break
              if i + size > arr.shape[0]:
                     break
              while j < arr.shape[1]:
                     # if the end of the matrix is reached, break
                     if j + size > arr.shape[1]:
                            break
                     # compute the average of the pooling matrix
                     _lowerCAmelCase     :				Dict       =							int(np.average(arr[i : i + size, j : j + size]       )       )
                     # shift the pooling matrix by stride of column pixels
                     j += stride
                     mat_j += 1

              # shift the pooling matrix by stride of row pixels
              i += stride
              mat_i += 1
              # reset the column index to 0
              _lowerCAmelCase     :				Optional[int]       =							0
              _lowerCAmelCase     :				int       =							0

       return updated_arr


# Main Function
if __name__ == "__main__":
       from doctest import testmod

       testmod(name="""avgpooling""", verbose=True)

       # Loading the image
       lowerCAmelCase     :  List[Any]											=    Image.open("""path_to_image""")

       # Converting the image to numpy array and maxpooling, displaying the result
       # Ensure that the image is a square matrix

       Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

       # Converting the image to numpy array and averagepooling, displaying the result
       # Ensure that the image is a square matrix

       Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()





'''simple docstring'''







import argparse

from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
from transformers.utils import logging


logging.set_verbosity_info()






def       lowercase					(_A ,    _A ,    _A       ):







       """simple docstring"""







       _lowerCAmelCase     :				Optional[Any]       =							TaConfig.from_json_file(_A       )
       print(f'Building PyTorch model from configuration: {config}'       )
       _lowerCAmelCase     :				Union[str, Any]       =							TaForConditionalGeneration(_A       )

       # Load weights from tf checkpoint
       load_tf_weights_in_ta(_A ,    _A ,    _A       )

       # Save pytorch-model
       print(f'Save PyTorch model to {pytorch_dump_path}'       )
       model.save_pretrained(_A       )


if __name__ == "__main__":
       lowerCAmelCase     :  str											=    argparse.ArgumentParser()
       # Required parameters
       parser.add_argument(
           """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
       )
       parser.add_argument(
           """--config_file""",
           default=None,
           type=str,
           required=True,
           help=(
               """The config json file corresponding to the pre-trained T5 model. \nThis specifies the model architecture."""
           ),
       )
       parser.add_argument(
           """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
       )
       lowerCAmelCase     :  int											=    parser.parse_args()
       convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)

