Skip to content

Commit

Permalink
fix FID metric
Browse files Browse the repository at this point in the history
Summary:
had to add a check in to see if num of real/fake images is bigger than 2 because otherwise we divided in zero in:
```real_cov = real_cov_num / (self.num_real_images - 1)```
and
```fake_cov = fake_cov_num / (self.num_fake_images - 1)```

Reviewed By: JKSenthil

Differential Revision: D49570353

fbshipit-source-id: b829d21fcc39c8a76d839349ab13cd2330fdf104
  • Loading branch information
hadarrotschield authored and facebook-github-bot committed Sep 24, 2023
1 parent ceb32b1 commit 301a3cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions torcheval/metrics/image/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ def compute(self: TFrechetInceptionDistance) -> Tensor:

# If the user has not already updated with at lease one
# image from each distribution, then we raise an Error.
if (self.num_real_images == 0) or (self.num_fake_images == 0):
if (self.num_real_images < 2) or (self.num_fake_images < 2):
warnings.warn(
"Computing FID requires at least 1 real image and 1 fake image,"
"Computing FID requires at least 2 real images and 2 fake images,"
f"but currently running with {self.num_real_images} real images and {self.num_fake_images} fake images."
"Returning 0.0",
RuntimeWarning,
Expand Down

0 comments on commit 301a3cb

Please sign in to comment.