




import math
import os

import cva
import numpy as np

UpperCamelCase__            =     255.0







def       _a (		SCREAMING_SNAKE_CASE_				:							float , SCREAMING_SNAKE_CASE_				:							float	):
					__lowerCAmelCase							  =			np.mean((original - contrast) ** 2	)
					if mse == 0:
										return 1_00

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







def       _a (		):
					__lowerCAmelCase							  =			os.path.dirname(os.path.realpath(SCREAMING_SNAKE_CASE_	)	)
					# Loading images (original image and compressed image)
					__lowerCAmelCase							  =			cva.imread(os.path.join(SCREAMING_SNAKE_CASE_ , "image_data/original_image.png"	)	)
					__lowerCAmelCase							  =			cva.imread(os.path.join(SCREAMING_SNAKE_CASE_ , "image_data/compressed_image.png"	) , 1	)

					__lowerCAmelCase							  =			cva.imread(os.path.join(SCREAMING_SNAKE_CASE_ , "image_data/PSNR-example-base.png"	)	)
					__lowerCAmelCase							  =			cva.imread(
					    os.path.join(SCREAMING_SNAKE_CASE_ , "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(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	)} dB"""	)

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


if __name__ == "__main__":
					main()










import json
import logging
import os
import subprocess
from argparse import ArgumentParser


UpperCamelCase__            =     logging.getLogger(__name__)







def       _a (		):
					__lowerCAmelCase							  =			ArgumentParser()
					__lowerCAmelCase  ,				__lowerCAmelCase							  =			parser.parse_known_args()
					for arg in unknown:
										if arg.startswith(("-", "--")	):
															parser.add_argument(arg.split("="	)[0]	)

					return parser.parse_args()







def       _a (		):
					__lowerCAmelCase							  =			parse_args()
					__lowerCAmelCase							  =			88_88
					__lowerCAmelCase							  =			int(os.environ["SM_NUM_GPUS"]	)
					__lowerCAmelCase							  =			json.loads(os.environ["SM_HOSTS"]	)
					__lowerCAmelCase							  =			len(SCREAMING_SNAKE_CASE_	)
					__lowerCAmelCase							  =			os.environ["SM_CURRENT_HOST"]
					__lowerCAmelCase							  =			hosts.index(SCREAMING_SNAKE_CASE_	)
					__lowerCAmelCase							  =			"INFO"

					if num_nodes > 1:
										__lowerCAmelCase							  =			F"""python -m torch.distributed.launch \
                --nnodes={num_nodes}  \
                --node_rank={rank}  \
                --nproc_per_node={num_gpus}  \
                --master_addr={hosts[0]}  \
                --master_port={port} \
                ./run_glue.py \
                {''.join(['nested fstring' for parameter,value in args.__dict__.items()]	)}"""
					else:
										__lowerCAmelCase							  =			F"""python -m torch.distributed.launch \
            --nproc_per_node={num_gpus}  \
            ./run_glue.py \
            {''.join(['nested fstring' for parameter,value in args.__dict__.items()]	)}"""
					try:
										subprocess.run(SCREAMING_SNAKE_CASE_ , shell=SCREAMING_SNAKE_CASE_	)
					except Exception as e:
										logger.info(SCREAMING_SNAKE_CASE_	)


if __name__ == "__main__":
					main()




