From 58258e4997bb5a049c8eb2671d5a3c6de1b1437c Mon Sep 17 00:00:00 2001 From: egoist945402376 Date: Mon, 22 Apr 2024 10:53:42 +0100 Subject: [PATCH] FID calculator used for evaluating generated images. --- tools/FID_calculator.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tools/FID_calculator.py diff --git a/tools/FID_calculator.py b/tools/FID_calculator.py new file mode 100644 index 0000000..083da89 --- /dev/null +++ b/tools/FID_calculator.py @@ -0,0 +1,30 @@ +import subprocess + + +def run_fid_command(generated_image_folder, dataset_image_folder, dim=2048): + + command = f'python -m pytorch_fid {generated_image_folder} {dataset_image_folder} --dim={dim}' + + try: + + result = subprocess.run(command, shell=True, check=True, text=True, capture_output=True) + + print("Successfully calculate FID score!") + print(result.stdout) + except subprocess.CalledProcessError as e: + print("Failed to calculate the FID score:") + print(e.stderr) + + +# Modify your path to dataset images folder and generated images folder. +generated_image_folder = 'path_to_generated_image_folder' +dataset_image_folder = 'path_to_dataset_image_folder' + + +# dimensions options: 768/ 2048 +# Choose 768 for fast calculation and reduced memory requirement +# choose 2048 for better calculation +# default: 2048 +dimensions = 2048 +# run +run_fid_command(generated_image_folder, dataset_image_folder, dimensions)