import numpy as np
import math
def cal_psnr():
quant_output = np.fromfile("./output/output.raw", dtype='uint16')
quant_output = quant_output.astype('float64')
compiled_output = np.fromfile("./output_mc50/dump_ocm_hsk_output_nhwc.raw", dtype='uint16')
compiled_output = compiled_output.astype('float64')
diff = quant_output - compiled_output
rmse = math.sqrt(np.mean(diff ** 2.))
eps = np.finfo(np.float64).eps
if(rmse == 0):
rmse = eps
else:
# 65535 = 2^16-1, because original data type is uint16
rmse = 20*math.log10(65535.0/rmse)
print(f"psnr = {rmse}")
if __name__ == "__main__":
cal_psnr()
python计算psnr
最新推荐文章于 2024-07-14 22:18:32 发布