GaParmar / clean-fid

PyTorch - FID calculation with proper image resizing and quantization steps [CVPR 2022]
https://www.cs.cmu.edu/~clean-fid/
MIT License
894 stars 68 forks source link

Can KID be negative number #36

Open chandrakanth-gudavalli opened 1 year ago

chandrakanth-gudavalli commented 1 year ago

I am trying to compute KID, but it is generating negative values. Can KID be a negative number?

Here is the code that I used: ` from cleanfid import fid fdir1 = my_folder1_path fdir2 = my_folder2_path

kid_score = fid.compute_kid(fdir1, fdir2) `

Each folder has only 6 images. My kid_score is -0.0406.

Could someone please help me understand why the KID is less that zero?

Thank you, Chandrakanth

GaParmar commented 1 year ago

Can you provide some more details about the setup?

-Gaurav

Jingyu6 commented 1 year ago

Can you provide some more details about the setup?

-Gaurav

Hi Gaurav,

I'm also encountering similar problems. In my case, I have N images for the ground truth set and 5 * N images for the synthesized set (N ranging from hundreds to thousands). I computed FID, CLIP-FID, and KID using the following APIs:

device = 'cuda' if torch.cuda.is_available() else 'cpu'
configs = {
    "fdir1": args.path_to_real_renderings, 
    "fdir2": args.path_to_synthesized_renderings, 
    "device": device
}

if "fid" in args.metrics:
    score = fid.compute_fid(**configs)
    print(f"FID score: {score}")
if "clip_fid" in args.metrics:
    score = fid.compute_fid(mode="clean", model_name="clip_vit_b_32", **configs)
    print(f"Clip FID score: {score}")
if "kid" in args.metrics:
    score = fid.compute_kid(**configs)
    print(f"KID score: {score}")

Here are some examples of FID, clip FID and KID score triplets where KIDs are negative: (8.6600, 0.3283, -0.000026705) (6.3603, 0.1913, -0.000053080) ...

Seems to me that there're some numerical error going on when the difference is small (like when FID is small to a certain degree)?

Best, Jingyu

chenguolin commented 10 months ago

I got the same problem. Any intuitive explanation? Or could we just take the absolute values? Thanks.