You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to calculate FID between the real and fake images, but the batch_size of fake images is 5 times the real ones (according to the traditional setting in layout2img), and the result is wrong. Then I checked the implementation of FID, which assumes the same batch_size when calculating the covariance, which is not suitable to my knowledge.
defcompute(self) ->Tensor:
"""Calculate FID score based on accumulated extracted features from the two distributions."""real_features=dim_zero_cat(self.real_features)
fake_features=dim_zero_cat(self.fake_features)
# computation is extremely sensitive so it needs to happen in double precisionorig_dtype=real_features.dtypereal_features=real_features.double()
fake_features=fake_features.double()
# calculate mean and covariancen=real_features.shape[0]
mean1=real_features.mean(dim=0)
mean2=fake_features.mean(dim=0)
diff1=real_features-mean1diff2=fake_features-mean2cov1=1.0/ (n-1) *diff1.t().mm(diff1) # the same n is usedcov2=1.0/ (n-1) *diff2.t().mm(diff2)
# compute fidreturn_compute_fid(mean1, cov1, mean2, cov2).to(orig_dtype)
Expected behavior
Environment
TorchMetrics version ( pip): 0.8.0
PyTorch Version :1.12.0a0+bd13bc6
Any other relevant information such as OS (e.g., Linux): docker environment, the image is highly based on nvcr.io/nvidia/pytorch:22.04-py3
Additional context
The text was updated successfully, but these errors were encountered:
FYI, the more suitable behavior might be something like the following code
defcompute(self) ->Tensor:
"""Calculate FID score based on accumulated extracted features from the two distributions."""real_features=dim_zero_cat(self.real_features)
fake_features=dim_zero_cat(self.fake_features)
# computation is extremely sensitive so it needs to happen in double precisionorig_dtype=real_features.dtypereal_features=real_features.double()
fake_features=fake_features.double()
# calculate mean and covariancen=real_features.shape[0]
m=fake_features.shape[0] ### newmean1=real_features.mean(dim=0)
mean2=fake_features.mean(dim=0)
diff1=real_features-mean1diff2=fake_features-mean2cov1=1.0/ (n-1) *diff1.t().mm(diff1)
cov2=1.0/ (m-1) *diff2.t().mm(diff2) ### change n to m# compute fidreturn_compute_fid(mean1, cov1, mean2, cov2).to(orig_dtype)
🐛 Bug
I want to calculate FID between the real and fake images, but the batch_size of fake images is 5 times the real ones (according to the traditional setting in layout2img), and the result is wrong. Then I checked the implementation of FID, which assumes the same batch_size when calculating the covariance, which is not suitable to my knowledge.
To Reproduce
Code sample
Here is the official implementation
Expected behavior
Environment
pip
): 0.8.0Additional context
The text was updated successfully, but these errors were encountered: