Skip to content

Commit

Permalink
dev(narugo): support furry model
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Nov 5, 2024
1 parent b69747a commit 9c994e6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions imgutils/validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .color import *
from .completeness import *
from .dbrating import *
from .furry import *
from .monochrome import *
from .nsfw import *
from .portrait import *
Expand Down
57 changes: 57 additions & 0 deletions imgutils/validate/furry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Overview:
A model for classifying anime furry images into 2 classes (``non_furry``, ``furry``).
The following are sample images for testing.
.. image:: furry.plot.py.svg
:align: center
This is an overall benchmark of all the furry classification models:
.. image:: furry_benchmark.plot.py.svg
:align: center
The models are hosted on
`huggingface - deepghs/anime_furry <https://huggingface.co/deepghs/anime_furry>`_.
"""
from typing import Tuple, Dict

from ..data import ImageTyping
from ..generic import classify_predict, classify_predict_score

__all__ = [
'anime_furry_score',
'anime_furry',
]

_DEFAULT_MODEL_NAME = 'mobilenetv3_v0.1_dist'
_REPO_ID = 'deepghs/anime_furry'


def anime_furry_score(image: ImageTyping, model_name: str = _DEFAULT_MODEL_NAME) -> Dict[str, float]:
"""
Get the scores for different types in a furry anime image.
:param image: The input image.
:type image: ImageTyping
:param model_name: The model name. Default is 'mobilenetv3_v0.1_dist'.
:type model_name: str
:return: A dictionary with type scores.
:rtype: Dict[str, float]
"""
return classify_predict_score(image, _REPO_ID, model_name)

Check warning on line 43 in imgutils/validate/furry.py

View check run for this annotation

Codecov / codecov/patch

imgutils/validate/furry.py#L43

Added line #L43 was not covered by tests


def anime_furry(image: ImageTyping, model_name: str = _DEFAULT_MODEL_NAME) -> Tuple[str, float]:
"""
Get the primary furry type and its score.
:param image: The input image.
:type image: ImageTyping
:param model_name: The model name. Default is 'mobilenetv3_v0.1_dist'.
:type model_name: str
:return: A tuple with the primary type and its score.
:rtype: Tuple[str, float]
"""
return classify_predict(image, _REPO_ID, model_name)

Check warning on line 57 in imgutils/validate/furry.py

View check run for this annotation

Codecov / codecov/patch

imgutils/validate/furry.py#L57

Added line #L57 was not covered by tests

0 comments on commit 9c994e6

Please sign in to comment.