imgutils.tagging.camie
- Overview:
This module provides functionality for image tagging using the Camie Tagger model, which can identify over 70,000 tags in images. The implementation is based on the Camais03/camie-tagger project, with ONNX optimizations available at deepghs/camie_tagger_onnx.
Note
The tagger categorizes tags into multiple types including rating, general, characters, year, meta, artist, and copyright. While rating, general, and character tags tend to be accurate, other tag types (year, meta, artist, copyright) have shown limited accuracy in testing and are not included in default outputs.
convert_camie_emb_to_prediction
- imgutils.tagging.camie.convert_camie_emb_to_prediction(emb: ndarray, model_name: str = 'initial', is_refined: bool = True, mode: Literal['balanced', 'high_precision', 'high_recall', 'micro_opt', 'macro_opt'] = 'balanced', thresholds: float | Dict[str, float] | None = None, no_underline: bool = False, drop_overlap: bool = False, fmt: Any = ('rating', 'general', 'character'))[source]
Convert stored embeddings back to tag predictions.
Useful for reprocessing existing embeddings with new thresholds or formats.
- Parameters:
emb (np.ndarray) – Embedding vector(s) from previous inference
model_name (str) – Original model variant name
is_refined (bool) – Whether embeddings come from refined stage, otherwise from initial stage
mode (CamieModeTyping) – Threshold selection strategy
thresholds (Optional[Union[float, Dict[str, float]]]) – Custom threshold values
no_underline (bool) – Remove underscores from tag names
drop_overlap (bool) – Remove overlapping tags in general category
fmt (Any) – Output format specification
- Returns:
Formatted results matching original prediction format
- Return type:
Any
Note
Modes for selection:
balanced
: Balanced precision/recallhigh_precision
: Higher precision thresholdshigh_recall
: Higher recall thresholdsmicro_opt
: Micro-optimized thresholdsmacro_opt
: Macro-optimized thresholds
For batch processing (2-dim input), returns a list where each element corresponds to one embedding’s predictions in the same format as single embedding output.
- Example:
>>> import numpy as np >>> from imgutils.tagging import get_camie_tags, convert_camie_emb_to_prediction >>> >>> # extract the feature embedding, shape: (W, ) >>> embedding = get_camie_tags('skadi.jpg', fmt='embedding') >>> >>> # convert to understandable result >>> rating, general, character = convert_camie_emb_to_prediction(embedding) >>> # these 3 dicts will be the same as that returned by `get_camie_tags('skadi.jpg')` >>> >>> # Batch processing, shape: (B, W) >>> embeddings = np.stack([ ... get_camie_tags('img1.jpg', fmt='embedding'), ... get_camie_tags('img2.jpg', fmt='embedding'), ... ]) >>> # results will be a list of (rating, general, character) tuples >>> results = convert_camie_emb_to_prediction(embeddings)