Skip to content

Commit

Permalink
Merge pull request #703 from FelixSteinbauer/patch-4
Browse files Browse the repository at this point in the history
Additional PSNR evaluations for the normalized synthesis case
  • Loading branch information
sarthakpati authored Aug 4, 2023
2 parents 6d901ee + b66a7c6 commit c2040ea
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions GANDLF/cli/generate_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,34 @@ def __percentile_clip(input_tensor, reference_tensor=None, p_min=0.5, p_max=99.5
gt_image_infill, output_infill
).item()

#TODO: use data_range=1.0 as parameter for PSNR when the Pull request is accepted that introduces the data_range parameter!
# PSNR - similar to pytorch PeakSignalNoiseRatio until 4 digits after decimal point
# torchmetrics PSNR using "max"
overall_stats_dict[current_subject_id]["psnr"] = peak_signal_noise_ratio(
gt_image_infill, output_infill
).item()

overall_stats_dict[current_subject_id]["psnr_eps"] = peak_signal_noise_ratio(
# same as above but with epsilon for robustness
overall_stats_dict[current_subject_id][
"psnr_eps"
] = peak_signal_noise_ratio(
gt_image_infill, output_infill, epsilon=sys.float_info.epsilon
).item()

# only use fix data range to [0;1] if the data was normalized before
if normalize:
# torchmetrics PSNR but with fixed data range of 0 to 1
overall_stats_dict[current_subject_id][
"psnr_01"
] = peak_signal_noise_ratio(
gt_image_infill, output_infill, data_range=1.0
).item()

# same as above but with epsilon for robustness
overall_stats_dict[current_subject_id][
"psnr_01_eps"
] = peak_signal_noise_ratio(
gt_image_infill, output_infill, epsilon=sys.float_info.epsilon
).item()

pprint(overall_stats_dict)
if outputfile is not None:
with open(outputfile, "w") as outfile:
Expand Down

0 comments on commit c2040ea

Please sign in to comment.