-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch size dependent FID #1620
Comments
Hi @nicolas-dufour, thanks for reporting this issue. |
Hi @SkafteNicki, thanks for checking this out. Hum that is strange! From further experiments, i found that the discrepancy disappeared when using float64. Maybe the problem is accelerator dependent? The previous experiment was done on a RTX 3090. Also, I've observed that the impact on FID was minimal for dataset size > 100. However, it's still weird that the metric changes with respect to the batch size. One solution would be to offer the option to run the embedding network at float64 precision. |
Hi again @nicolas-dufour, from torchmetrics.image.fid import NoTrainInceptionV3, FrechetInceptionDistance
import torch
metric = FrechetInceptionDistance()
metric.set_dtype(torch.float64)
imgs = torch.randn(1, 3, 256, 256)
imgs = ((imgs.clamp(-1, 1) / 2 + 0.5) * 255).to(torch.uint8)
metric.inception(imgs) still need a bit of testing a documentation. |
…lp numerical issues with inception feature extractor and its output variation due to the batch size. fix #43, related in torchmetrics: - Lightning-AI/torchmetrics#1620 - Lightning-AI/torchmetrics#1628 add explicit eval in the inception fe to help a case if someone copies just that file for metrics evaluation add explicit require_grad(False) to clip feature extractor add test cases to troubleshoot batch size dependence of metrics values
…lp numerical issues with inception feature extractor and its output variation due to the batch size. fix #43, related in torchmetrics: - Lightning-AI/torchmetrics#1620 - Lightning-AI/torchmetrics#1628 add explicit eval in the inception fe to help a case if someone copies just that file for metrics evaluation add explicit require_grad(False) to clip feature extractor add test cases to troubleshoot batch size dependence of metrics values
🐛 Bug
As pointed out by @kimihailv in #1198, FID seem to be batch-size dependent.
After some experimentation, the dependency seems to be linked to the inception network.
To Reproduce
If one runs:
We then have:
To be noted that when replacing
by
the FID is again batch independent. However, this is not a possible fix. Indeed, first this is very ineficient. Also, from experimentation, the batch bias in FID seems to be higher from small batch-sizes. If we compute FID between 2 uniformly sampled distributions with a 1000 points each, if we compute it with a batch size of 1000, we get FID 1.9 but if we compute it with batch-size=2, then the FID is 10. Since we sample from the same distribution, FID should be as close too zero as possible.
Expected behavior
FID computation should be batch_size independent
Environment
conda
,pip
, build from source): 0.10.3The text was updated successfully, but these errors were encountered: