Implementation:AUTOMATIC1111 Stable diffusion webui DeepDanbooru Tagger
| Knowledge Sources | |
|---|---|
| Domains | Image_Tagging, Deep_Learning |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
Implements the DeepDanbooru anime-style image tagger that predicts Danbooru tags from input images using a pretrained ResNet model.
Description
The DeepDanbooru Tagger module wraps the TorchDeepDanbooru model to predict anime-style tags for input images. The DeepDanbooru class manages the model lifecycle including lazy loading from a remote URL, device placement (moving between CPU and GPU as needed), and memory cleanup. The tag method is the main entry point that processes a single PIL image: it resizes the image to 512x512, runs inference through the model, and filters the resulting tag probabilities against a configurable threshold. Tags can be sorted alphabetically or by probability, formatted with spaces instead of underscores, escaped for prompt syntax, optionally include probability ranks, and filtered against a user-defined exclusion list. Rating tags are always excluded. A module-level singleton model instance is created for reuse.
Usage
Use this module to automatically generate Danbooru-style tags from images, typically as part of the interrogation pipeline for reverse-engineering prompts from existing images.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/deepbooru.py
- Lines: 1-98
Signature
class DeepDanbooru:
def __init__(self) -> None
def load(self) -> None
def start(self) -> None
def stop(self) -> None
def tag(self, pil_image) -> str
def tag_multi(self, pil_image, force_disable_ranks=False) -> str
Import
from modules.deepbooru import model
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pil_image | PIL.Image | Yes | The input image to tag |
| force_disable_ranks | bool | No | When True, suppresses probability scores even if enabled in settings |
Outputs
| Name | Type | Description |
|---|---|---|
| tags | str | A comma-separated string of predicted tags, optionally with probability weights |
Usage Examples
from modules.deepbooru import model
from PIL import Image
image = Image.open("example.png")
# Get tags as a comma-separated string
tags = model.tag(image)
print(tags) # e.g., "1girl, long_hair, blue_eyes, school_uniform"