Skip to content
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

CLIP-IQA functions are incorrectly typed #2951

Closed
wooseopkim opened this issue Feb 12, 2025 · 1 comment · Fixed by #2952
Closed

CLIP-IQA functions are incorrectly typed #2951

wooseopkim opened this issue Feb 12, 2025 · 1 comment · Fixed by #2952
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@wooseopkim
Copy link
Contributor

🐛 Bug

Currently, there are two diffrent interfaces for CLIP-IQA. One's a "module interface" or a Python class, and the other's functional. The problem is that, for the both interfaces, prompts parameter is incorrectly typed. It is supposed to be a tuple, each item being str or tuple[str, str]. But the current type hint is tuple[Union[str, tuple[str, str]], which indicates a tuple with a single item.

To Reproduce

Steps to reproduce the behavior...

Code sample

As long as this issue stays unresolved, you'd be able to read the GHA check-code result of my fork here.

# add this below the functional interface declaration (src/torchmetrics/functional/multimodal/clip_iqa.py)
if TYPE_CHECKING:
    from typing import Any, cast
    images = cast(Any, None)
    from functools import partial
    f = partial(clip_image_quality_assessment, images=images)
    f(prompts=("colorfullness",))
    f(prompts=("quality", "brightness", "noisiness"),)
    f(prompts=("quality", "brightness", "noisiness", "colorfullness"),)
    f(prompts=(("Photo of a cat", "Photo of a dog"), "quality", ("Colorful photo", "Black and white photo")))
# add this below the module interface declaration (src/torchmetrics/multimodal/clip_iqa.py)
if TYPE_CHECKING:
    from typing import cast
    images = cast(Any, None)
    f = CLIPImageQualityAssessment
    f(prompts=("colorfullness",))
    f(prompts=("quality", "brightness", "noisiness"),)
    f(prompts=("quality", "brightness", "noisiness", "colorfullness"),)
    f(prompts=(("Photo of a cat", "Photo of a dog"), "quality", ("Colorful photo", "Black and white photo")))
# run mypy command
mypy

Expected behavior

There should be no type error in the code above, as the arguments are directly pulled from the test code.

Environment

  • TorchMetrics version (if build from source, add commit SHA): d927909
  • Python & PyTorch Version (e.g., 1.0): Python 3.9, and Torch 2.5.1 if that matters
  • Any other relevant information such as OS (e.g., Linux): N/A

Additional context

I'm also submitting a PR for this.

@wooseopkim wooseopkim added bug / fix Something isn't working help wanted Extra attention is needed labels Feb 12, 2025
Copy link

Hi! Thanks for your contribution! Great first issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant