Skip to content

Introduce torchmetrics in place of piq in one place #2139

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

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
"pydantic-settings",
"requests",
"requests-mock",
"torchmetrics",
"torchvision",
"tzdata; sys_platform=='win32'",
"vws-auth-tools",
Expand Down Expand Up @@ -84,7 +85,6 @@ optional-dependencies.dev = [
"sphinxcontrib-spelling==8",
"sybil==6.1.1",
"tenacity==8.4.2",
"torch==2.3.1",
"types-docker==7.1.0.20240626",
"types-pillow==10.2.0.20240520",
"types-pyyaml==6.0.12.20240311",
Expand Down
19 changes: 8 additions & 11 deletions src/mock_vws/image_matchers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""Matchers for query and duplicate requests."""

import io
from typing import TYPE_CHECKING, Protocol, runtime_checkable
from typing import Protocol, runtime_checkable

import piq # type: ignore[import-untyped]
from PIL import Image
from torchmetrics.image import (
StructuralSimilarityIndexMeasure,
)
from torchvision.transforms import functional # type: ignore[import-untyped]

if TYPE_CHECKING:
import torch


@runtime_checkable
class ImageMatcher(Protocol):
Expand Down Expand Up @@ -81,12 +80,10 @@ def __call__(
first_image_tensor_batch_dimension = first_image_tensor.unsqueeze(0)
second_image_tensor_batch_dimension = second_image_tensor.unsqueeze(0)

# See https://github.com/photosynthesis-team/piq/pull/377
# for fixing the type hint in ``piq``.
ssim_value: torch.Tensor = piq.ssim( # pyright: ignore[reportAssignmentType]
x=first_image_tensor_batch_dimension,
y=second_image_tensor_batch_dimension,
data_range=1.0,
ssim = StructuralSimilarityIndexMeasure(data_range=1.0)
ssim_value = ssim(
first_image_tensor_batch_dimension,
second_image_tensor_batch_dimension,
)
ssim_score = ssim_value.item()

Expand Down
Loading