8000 Fid Metric by gucifer · Pull Request #2029 · pytorch/ignite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fid Metric #2029

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

Closed
wants to merge 59 commits into from
Closed

Fid Metric #2029

wants to merge 59 commits into from

Conversation

gucifer
Copy link
Contributor
@gucifer gucifer commented Jun 3, 2021

Description:
First implementation and tests for the FID metric.
Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added the module: metrics Metrics module label Jun 3, 2021
@gucifer
Copy link
Contributor Author
gucifer commented Jun 3, 2021

Mypy error is cause scipy and torchvision do not exist in typeshed
typeshed in type hint database of mypy
https://stackoverflow.com/questions/60716482/error-skipping-analyzing-flask-mysqldb-found-module-but-no-type-hints-or-lib
What should I do?

@gucifer
Copy link
Contributor Author
gucifer commented Jun 3, 2021

Mypy error is cause scipy and torchvision do not exist in typeshed
typeshed in type hint database of mypy
https://stackoverflow.com/questions/60716482/error-skipping-analyzing-flask-mysqldb-found-module-but-no-type-hints-or-lib
What should I do?

nvm.... found the fix. Updated mypy.ini file.


class InceptionExtractor:
def __init__(self) -> None:
from torchvision import models
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should tnink better how to handle this dependency without making it as a hard requirement.

) -> float:

diff = mu1 - mu2
import scipy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very unfriendly way to do things. This method is called after 1 epoch done and user get ImportError after some computational time. We should avoid this way of coding things!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just means that we have updated the mean and covariance based on all the training example given by user so far. Even if compute gives error as soon as user imports scipy they can rerun it and no computation done previously is lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where fid_score function is independently invoked, there is no extra computation so all cases are covered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use exception and a user friendly message whether scipy is missing.

from sklearn.metrics import cohen_kappa_score # noqa: F401

from ignite.metric.GAN import FID
import torch

train, test = torch.rand(10,2048), torch.rand(10,2048)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it relevant as shape for the standard FID metric ?
Namings as train, test seem to be unconventional, we can put either put y_pred/y or fake/real

8000
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FID is not just for image generation but also augmentation, style and feature transfer. In such cases real or fake is not appropriate. I will use y_pred/y instead.

self.model.eval()

def __call__(self, data: torch.Tensor) -> torch.Tensor:
if data.shape[1:] != (3, 299, 299):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If inception model is headless (no fully-connected layer), can't we use any size input. In the metric code we just have to ensure that we always have the same size...

Copy link
Contributor Author
@gucifer gucifer Jun 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

299x299 is minimum size of image needed and what is used for standard Inception model while calculating fid and IS. I can change it to >= 299 if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If inception model is headless (no fully-connected layer), can't we use any size input.

That's right !

In the metric code we just have to ensure that we always have the same size...

The user gives the feature size, so there is a test on shapes during iteration.

pynvml
clearml
scikit-image
py-rouge
nltk
pytorch_fid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have it twice. See above.

@KickItLikeShika
Copy link
Contributor
KickItLikeShika commented Jun 7, 2021

Friendly advice:

  • It will be way better and you will save a lot of time for yourself if you ran the tests locally, for example:
pytest tests/ignite/metrics/gan/test_fid.py

For more info about running tests and running distributed tests: https://github.com/pytorch/ignite/blob/master/CONTRIBUTING.md#run-tests

  • You had some issues with distributed tests before in this PR, as I was struggling a lot with DDP stuff (and still), but this page here I always use it as a reference, It will help you understand all the collective ops, try to have a look on it: https://pytorch.org/tutorials/intermediate/dist_tuto.html

Hope my advice helps you.

@gucifer gucifer closed this Jun 9, 2021
@gucifer gucifer reopened this Jun 9, 2021
@gucifer gucifer closed this Jun 9, 2021
@gucifer gucifer deleted the fid branch June 9, 2021 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: metrics Metrics module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0