Skip to content

Commit

Permalink
dev(narugo): add seq mode && remove support for Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Jan 26, 2024
1 parent a82637e commit 05e5033
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ jobs:
- 'windows-latest'
- 'macos-latest'
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
exclude:
- os: 'macos-latest'
python-version: '3.7'

steps:
- name: Get system version for Linux
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/installation/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation
===================

sdeval is currently hosted on PyPI. It required python >= 3.7.
sdeval is currently hosted on PyPI. It required python >= 3.8.

You can simply install sdeval from PyPI with the following command:

Expand Down
15 changes: 12 additions & 3 deletions sdeval/fidelity/ccip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
See `imgutils.metrics.ccip <https://deepghs.github.io/imgutils/main/api_doc/metrics/ccip.html>`_ for more information.
"""
import warnings
from typing import List, Optional
from typing import List, Optional, Literal, Union

import numpy as np
from PIL import Image
Expand Down Expand Up @@ -59,7 +59,8 @@ def __init__(self, images: ImagesTyping, feats: Optional[np.ndarray] = None, mod
raise ValueError(f'Feature shape should be (B, 768), but {feats.shape!r} found actually.')
self._features = list(feats)

def score(self, images: ImagesTyping, silent: bool = None) -> float:
def score(self, images: ImagesTyping, silent: bool = None,
mode: Literal['mean', 'seq'] = 'mean') -> Union[float, np.ndarray]:
"""
Calculate the similarity score between the reference dataset and a set of input images.
Expand All @@ -69,6 +70,9 @@ def score(self, images: ImagesTyping, silent: bool = None) -> float:
:type images: ImagesTyping
:param silent: If True, suppresses progress bars and additional output during calculation.
:type silent: bool
:param mode: Mode of the return value. Return a float value when ``mean`` is assigned,
return a numpy array when ``seq`` is assigned. Default is ``mean``.
:type mode: Literal['mean', 'seq']
:return: The similarity score between the reference dataset and the input images.
:rtype: float
Expand All @@ -85,5 +89,10 @@ def score(self, images: ImagesTyping, silent: bool = None) -> float:

diffs = ccip_batch_differences([*self._features, *_features])
matrix = diffs[:len(self._features), len(self._features):]
seq = (matrix < self._threshold).meax(axis=0)
assert seq.shape == (len(_features),)

return (matrix < self._threshold).mean().item()
if mode == 'seq':
return seq
else:
return seq.mean().item()
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _load_req(file: str):
url='https://github.com/deepghs/sdeval',

# environment
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=requirements,
tests_require=group_requirements['test'],
extras_require=group_requirements,
Expand All @@ -61,7 +61,6 @@ def _load_req(file: str):
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand Down

0 comments on commit 05e5033

Please sign in to comment.