[docs]defmae(a1,a2):try:asserta1.shape==a2.shape,f"Inputs must have the same shape, not {a1.shape} and {a2.shape}."asserta1.dtype==a2.dtype,f"Inputs must ahve the same dtype, not {a1.dtype} and {a2.dtype}."returnnp.mean(np.abs(a1-a2))exceptExceptionase:logger.error(f"Could not calculate MAE from inputs.\nEXCEPTION: {e}")raiseFLAMEEvalError(f"Could not calculate MAE from inputs.\nEXCEPTION: {e}")
[docs]defmse(a1,a2):try:asserta1.shape==a2.shape,f"Inputs must have the same shape, not {a1.shape} and {a2.shape}."asserta1.dtype==a2.dtype,f"Inputs must ahve the same dtype, not {a1.dtype} and {a2.dtype}."returnnp.mean((a1-a2).astype(np.float128)**2)exceptExceptionase:logger.error(f"Could not calculate MSE from inputs.\nEXCEPTION: {e}")raiseFLAMEEvalError(f"Could not calculate MSE from inputs.\nEXCEPTION: {e}")
[docs]defssim(a1,a2,channel_axis=2):try:asserta1.shape==a2.shape,f"Inputs must have the same shape, not {a1.shape} and {a2.shape}."asserta1.dtype==a2.dtype,f"Inputs must ahve the same dtype, not {a1.dtype} and {a2.dtype}."returnstructural_similarity(im1=a1,im2=a2,data_range=np.max([np.max(a1),np.max(a2)]),channel_axis=channel_axis,gradient=False,# means that the gradient SSIM will not be returnedfull=False,# means that the full SSIM image will not be returned)exceptExceptionase:logger.error(f"Could not calculate SSIM from inputs.\nEXCEPTION: {e}")raiseFLAMEEvalError(f"Could not calculate SSIM from inputs.\nEXCEPTION: {e}")