imgutils.tagging.overlap

drop_overlap_tags

imgutils.tagging.overlap.drop_overlap_tags(tags: List[str] | Mapping[str, float]) List[str] | Mapping[str, float][source]

Drop overlapping tags from the given list of tags.

This function removes tags that have overlaps with other tags based on precomputed overlap information.

Parameters:

tags (List[str]) – A list of tags.

Returns:

A list of tags without overlaps.

Return type:

List[str]

Examples::
>>> from imgutils.tagging import drop_overlap_tags
>>>
>>> tags = [
...     '1girl', 'solo',
...     'long_hair', 'very_long_hair', 'red_hair',
...     'breasts', 'medium_breasts',
... ]
>>> drop_overlap_tags(tags)
['1girl', 'solo', 'very_long_hair', 'red_hair', 'medium_breasts']
>>>
>>> tags = {
...     '1girl': 0.8849405313291128,
...     'solo': 0.8548297594823425,
...     'long_hair': 0.03910296474461261,
...     'very_long_hair': 0.6615180440330748,
...     'red_hair': 0.21552028866308015,
...     'breasts': 0.3165260620737027,
...     'medium_breasts': 0.47744464927382957,
... }
>>> drop_overlap_tags(tags)
{
    '1girl': 0.8849405313291128,
    'solo': 0.8548297594823425,
    'very_long_hair': 0.6615180440330748,
    'red_hair': 0.21552028866308015,
    'medium_breasts': 0.47744464927382957
}