What Is DeepDanbooru in AUTOMATIC1111 and How It Generates Anime-Style Prompt Tags
DeepDanbooru is an integrated TensorFlow/PyTorch-based image tagger in AUTOMATIC1111’s Stable Diffusion WebUI that analyzes images to produce Danbooru-style tags for anime prompt engineering.
DeepDanbooru is an optional component within the AUTOMATIC1111/stable-diffusion-webui repository that enables automatic tagging of images using the same taxonomy as the anime image board Danbooru. By loading a pretrained ResNet model, it generates descriptive tags that users can paste directly into prompts to achieve consistent anime-style generations.
How DeepDanbooru Works in AUTOMATIC1111
The core implementation resides in modules/deepbooru.py, where the DeepDanbooru class manages model loading and inference. When first invoked, the system downloads the model-resnet_custom_v3.pt file into the models/torch_deepdanbooru directory and instantiates a DeepDanbooruModel object.
The class maintains the model on CPU by default, moving it to the active compute device only during the start() and stop() lifecycle methods to conserve VRAM.
The Tag Generation Pipeline
The tag_multi() method orchestrates the inference pipeline. First, the input PIL.Image is resized to 512×512 pixels and normalized to a NumPy float array with values scaled to [0, 1]. The tensor passes through the ResNet model under torch.no_grad() context, producing a probability vector for each tag in the Danbooru taxonomy.
Post-processing applies several filters configured via modules/shared_options.py. Tags with probabilities below shared.opts.interrogate_deepbooru_score_threshold are discarded, and any tag beginning with the rating: prefix is automatically excluded. Results are then sorted either alphabetically via deepbooru_sort_alpha or by descending confidence score.
Configuring DeepDanbooru Settings
All user-controllable parameters are defined in modules/shared_options.py and exposed in the WebUI settings panel. Key options include:
interrogate_deepdanbooru_score_threshold: Minimum confidence score (default 0.35) for tag inclusiondeepbooru_use_spaces: Replaces underscores with spaces in output tagsdeepbooru_escape: Escapes parentheses for Stable Diffusion compatibilitydeepbooru_sort_alpha: Sorts tags alphabetically rather than by probabilitydeepbooru_filter_tags: Comma-separated list of tags to explicitly exclude
Generating Anime-Style Prompts with DeepDanbooru
Users can invoke DeepDanbooru through three primary interfaces to automatically populate prompts with anime-specific descriptors.
Via the WebUI Interface
The interface provides a "Generate tags" button in the img2img or Extras tabs. Clicking this processes the uploaded image and inserts the resulting comma-separated tag list into the prompt field, ready for generation.
Via the REST API
The REST endpoint defined in modules/api/api.py exposes DeepDanbooru through the interrogateapi function. Sending a POST request to /sdapi/v1/interrogate with the model parameter set to "deepdanbooru" returns the generated tags.
curl -X POST http://localhost:7860/sdapi/v1/interrogate \
-H "Content-Type: application/json" \
-d '{"model":"deepdanbooru","image":"'$(base64 -w 0 anime.png)'"}'
The JSON response contains a caption field with the formatted tags.
Programmatic Usage in Python
For internal scripting or extensions, access the singleton instance via deepbooru.model:
from modules import deepbooru, images
# Load image as PIL Image
pil_img = images.open_image("input_anime.png")
# Generate tags string
tags = deepbooru.model.tag(pil_img)
print(tags)
The tag() method handles device placement and formatting automatically based on the current settings.
Summary
- DeepDanbooru is implemented in
modules/deepbooru.pyas a ResNet-based tagger usingmodel-resnet_custom_v3.pt - The
tag_multi()method processes 512×512 images, filters by confidence threshold, and excludesrating:prefixes - Configuration options in
modules/shared_options.pycontrol formatting, sorting, and filtering behavior - Access via WebUI button, REST API (
/sdapi/v1/interrogatewithmodel="deepdanbooru"), or Pythondeepbooru.model.tag() - Tags follow the Danbooru taxonomy optimized for anime-style prompt engineering
Frequently Asked Questions
What is the difference between DeepDanbooru and BLIP in AUTOMATIC1111?
DeepDanbooru uses a ResNet model trained on Danbooru tags to output anime-specific descriptors like 1girl or blue_hair, while BLIP generates natural language captions. DeepDanbooru is optimized for anime prompt engineering, whereas BLIP suits photorealistic or general descriptions.
How do I exclude rating tags from DeepDanbooru results?
The tag_multi() method automatically filters out any tag starting with rating: (e.g., rating:safe, rating:explicit). This behavior is hardcoded in modules/deepbooru.py and requires no user configuration.
Can I use DeepDanbooru without launching the full WebUI?
While DeepDanbooru is integrated into the WebUI ecosystem, you can import the module in a Python environment where the WebUI dependencies are installed. Use from modules import deepbooru and call deepbooru.model.tag() after ensuring the model file is present in models/torch_deepdanbooru/.
Where does AUTOMATIC1111 store the DeepDanbooru model file?
The model model-resnet_custom_v3.pt is downloaded to models/torch_deepdanbooru/ within the WebUI root directory when first used, as handled by the modelloader.load_models call in modules/deepbooru.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →