Introduction to DeepDanbooru
DeepDanbooru is an innovative system designed to estimate tags for anime-style girl images. Developed using Python 3.11, this tool allows users to categorize and analyze images efficiently. For those interested in seeing it in action, a live demo is available at the DeepDanbooru Web.
Requirements
DeepDanbooru relies on a few Python packages to function effectively. To get started, the following dependencies must be installed:
- Click (version 8.1.7 or newer)
- numpy (version 1.26.4 or newer)
- requests (version 2.32.3 or newer)
- scikit-image (version 0.24.0 or newer)
- six (version 1.16.0 or newer)
- tensorflow (version 2.17.0 or newer)
- tensorflow-io (version 0.31.0 or newer)
These can be quickly installed using the requirements.txt
file by running the command:
> pip install -r requirements.txt
Alternatively, DeepDanbooru can be installed with pip. Note that TensorFlow is not included by default. To include it, use the following commands:
> # default installation
> pip install .
> # with tensorflow package
> pip install .[tensorflow]
Usage
DeepDanbooru requires some preparatory steps before it can be used for training and evaluation:
-
Prepare a Dataset: If you don't have an existing dataset, use DanbooruDownloader to download one from Danbooru.
-
Create a Training Project Folder:
> deepdanbooru create-project [your_project_folder]
-
Prepare a Tag List: To obtain the latest tags from the Danbooru server, the following command can be used (account and API key required):
> deepdanbooru download-tags [your_project_folder] --username [your_danbooru_account] --api-key [your_danbooru_api_key]
-
Optional Dataset Filtering: Convert optional tags (such as rating and score) into system tags if desired:
> deepdanbooru make-training-database [your_dataset_sqlite_path] [your_filtered_sqlite_path]
-
Modify the
project.json
File: Update thedatabase_path
setting to point to the actual SQLite file path. -
Start Training:
> deepdanbooru train-project [your_project_folder]
-
Evaluate the System:
> deepdanbooru evaluate [image_file_path or folder]... --project-path [your_project_folder] --allow-folder
Dataset Structure
The input dataset for DeepDanbooru follows a specific folder structure. The core component is an SQLite database file, which should include a particular table structure as detailed below:
- Main Folder: Contains an
images
subfolder and the SQLite file (*.sqlite
). - Images Folder: Images are stored in subfolders named after the first two characters of their filename.
Example structure:
MyDataset/
├── images/
│ ├── 00/
│ │ ├── 00000000000000000000000000000000.jpg
│ │ ├── ...
│ ├── 01/
│ │ ├── 01000000000000000000000000000000.jpg
│ │ ├── ...
│ └── ff/
│ ├── ff000000000000000000000000000000.jpg
│ ├── ...
└── my-dataset.sqlite
The database file should have the following table structure:
posts
├── id (INTEGER)
├── md5 (TEXT)
├── file_ext (TEXT)
├── tag_string (TEXT)
└── tag_count_general (INTEGER)
Each image filename must match the format [md5].[file_ext]
. The tag_string
is a space-separated list of tags, such as 1girl ahoge long_hair
. The tag_count_general
setting is used to filter images based on their tag count for training purposes.
Project Structure
Each training project in DeepDanbooru is organized into a folder that contains essential configuration files, such as project.json
and tags.txt
.
project.json
: Describes general settings and paths for the project.tags.txt
: Lists all tags that the system will use for estimation. This file should be a simple list of tags, each on a new line.
Example content of tags.txt
:
1girl
ahoge
...
With this setup, DeepDanbooru provides a robust platform for creating and testing anime-style image tag estimation models.