




import argparse

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


logging.set_verbosity_info()





def 							lowerCamelCase    (							UpperCAmelCase_	:      Optional[int]   ,       UpperCAmelCase_	:      int   ,       UpperCAmelCase_	:      List[str]      )->			Union[str, Any]:

       """simple docstring"""




       a			   =TaConfig.from_json_file(UpperCAmelCase_      )
       print(F'''Building PyTorch model from configuration: {config}'''      )
       a			   =TaForConditionalGeneration(UpperCAmelCase_      )

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

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


if __name__ == "__main__":
    _lowerCamelCase							=      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							=      parser.parse_args()
    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)






import math
import os

import cva
import numpy as np

_lowerCamelCase							=      255.0





def 							lowerCamelCase    (							UpperCAmelCase_	:      float   ,       UpperCAmelCase_	:      float      )->			float:

       """simple docstring"""




       a			   =np.mean((original - contrast) ** 2      )
       if mse == 0:
              return 100

       return 20 * math.logaa(PIXEL_MAX / math.sqrt(UpperCAmelCase_      )      )





def 							lowerCamelCase    (							)->			None:

       """simple docstring"""




       a			   =os.path.dirname(os.path.realpath(UpperCAmelCase_      )      )
       # Loading images (original image and compressed image)
       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/original_image.png"""      )      )
       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/compressed_image.png"""      )   ,       1      )

       a			   =cva.imread(os.path.join(UpperCAmelCase_   ,       """image_data/PSNR-example-base.png"""      )      )
       a			   =cva.imread(
           os.path.join(UpperCAmelCase_   ,       """image_data/PSNR-example-comp-10.jpg"""      )   ,       1      )

       # Value expected: 29.73dB
       print("""-- First Test --"""      )
       print(F'''PSNR value is {peak_signal_to_noise_ratio(UpperCAmelCase_   ,       UpperCAmelCase_      )} dB'''      )

       # # Value expected: 31.53dB (Wikipedia Example)
       print("""\n-- Second Test --"""      )
       print(F'''PSNR value is {peak_signal_to_noise_ratio(UpperCAmelCase_   ,       UpperCAmelCase_      )} dB'''      )


if __name__ == "__main__":
    main()
