Automated LoRA Dataset Creation: Extract, Filter, Tag, QA
Build LoRA training sets from anime video and generative tools — automated extraction, tagging, and quality checks that keep the dataset clean.
On this page
Automated LoRA Dataset Creation: Extract, Filter, Tag, QA
TL;DR
- Extract I-frames from anime episodes with
ffmpeg -vf select=eq(pict_type\,I)— they align closely with animation keyframes and give you thousands of candidate images. - Auto-tag frames with DeepDanbooru (TensorFlow model trained on Danbooru 2021 data) using
load_model_from_project,load_tags_from_project, andload_image_for_evaluate; filter by Booru tags (1girl,red_hair, character names) to isolate a single character. - Prune the resulting folder to 20–50 diverse images: remove wrong characters, multi-character shots, duplicate sequences, OP/ED frames, tweens, and low-quality crops.
- Alternatively, generate synthetic sets with ChatGPT Plus / DALL-E 3 using a prompt template with a
[SUBJECT]placeholder; expect long filenames and occasional grid outputs.
Why automation matters
Training a character LoRA starts with a dataset. Hand-picking and captioning 30–50 images from scratch is tedious enough that many people never finish. Two automation paths exist:
- Video → frames → tags → filter → prune — turn an anime series into a character-specific dataset.
- Prompt template → DALL-E 3 → download → rename → curate — synthesize a concept dataset from scratch.
Both produce a folder of images paired with .txt caption files. Extracted frames are on-model but noisy; generated images are clean but may drift off-model. Pick the path that matches your source material. The choice between paths depends on your source material. If you already have anime episode files on disk, Path A will produce images that are authentically on-model. If you want something that does not yet exist as reference footage — a custom concept, a specific object style, or a character from your own designs — Path B lets you generate training data from a text description. Both approaches scale differently: Path A is bounded by the episodes you own; Path B is bounded only by your patience with per-request rate limits.
Path A: Anime video to character dataset
Requirements
- ffmpeg — on
PATH. - Python 3.8+ — for the orchestration scripts.
- Video files — MKV/MP4/WebM without hardcoded subtitles. If you can toggle subs off in your player, you are fine.
- Disk space — a 12-episode 1080p series can yield tens of gigabytes of PNG keyframes; actual size depends on GOP settings in the source encode. The original guide author estimated roughly 30 GB for a typical 12-episode 1080p series.
Extract I-frames only
Video codecs store full frames (I-frames) at scene changes and at regular GOP intervals. Anime keyframes — the drawings that define a pose — often coincide with those scene changes. The select filter keeps only I-frames:
ffmpeg -i episode.mkv -vf "select=eq(pict_type\,I)" -vsync vfr "episode-%06d.png"
The flag select=eq(pict_type\,I) keeps frames where pict_type == I. The -vsync vfr flag produces variable-rate output to avoid duplicated frames. Output naming uses %06d for zero-padded sequence numbers. This command syntax is confirmed by Stack Overflow.
The article author notes a critical distinction: anime keyframes (the artist's defining poses) and video keyframes / I-frames (full compressed frames) are not the same concept. However, in practice, video I-frames are placed at scene changes, which often align with anime keyframes. This alignment means extracting I-frames yields a set enriched for on-model drawings, even though it also captures some in-between frames that happened to land on a GOP boundary.
Batch-process a folder with a short Python loop (see the source guide for a full script).
The extractor script from the source article iterates every file in the input folder, matches common video extensions (.avi, .mp4, .mkv, .ogm, .webm), and runs the ffmpeg command for each episode. This batch approach means a 12-episode series can be processed unattended. The output directory structure mirrors the input filenames: each episode produces its own numbered sequence (e.g., Magical Girl Lyrical Nanoha - S04E01.mkv-000007.png), making it easy to trace any frame back to its source episode and timestamp.
Auto-tag with DeepDanbooru
DeepDanbooru is a multi-label TensorFlow classifier that outputs Danbooru-style tags. The pretrained model (release v3-20211112-sgd-e28) was trained on Danbooru data from November 2021 using the SGD optimizer. The repository describes it as an "AI based multi-label girl image classification system, implemented by using TensorFlow." Install:
pip install git+https://github.com/KichangKim/DeepDanbooru.git
pip install tensorflow tensorflow-io
Key API functions from the repo source:
load_model_from_project(path, compile_model=False)— loads the.keras/.h5model from a project folder. Signature confirmed inproject.py.load_tags_from_project(path)— readstags.txt(newline-separated) from the project.load_tags(path)— generic tag-file loader used by the two above. Implementation indata/dataset.py.load_image_for_evaluate(path, width, height)— loads, resizes (preserving aspect + padding), normalizes to[0,1]; returnsnp.ndarray. Signature confirmed indata/__init__.py.
Tagging script outline (from article 218):
import deepdanbooru
import os
model = deepdanbooru.project.load_model_from_project(model_path, compile_model=False)
tags = deepdanbooru.project.load_tags_from_project(model_path)
tags_char = deepdanbooru.data.load_tags(os.path.join(model_path, "tags-character.txt"))
tags_gen = deepdanbooru.data.load_tags(os.path.join(model_path, "tags-general.txt"))
for frame in frames:
img = deepdanbooru.data.load_image_for_evaluate(
frame, width=model.input_shape[2], height=model.input_shape[1]
)
probs = model.predict(img[None, ...])[0]
keep = [tags[i] for i, p in enumerate(probs) if p >= 0.5]
char_tags = [t for t in keep if t in tags_char]
gen_tags = [t for t in keep if t in tags_gen]
with open(frame.replace(".png", ".txt"), "w") as f:
f.write(", ".join(t.replace("_", " ") for t in set(char_tags + gen_tags)))
Note on tag files. The repository README documents only tags.txt. The code references tags-character.txt and tags-general.txt, which may exist inside the release ZIP assets. If they are missing from your download, split tags.txt yourself or filter by known prefixes.
The tagging script separates character tags from general tags, which is essential for the filtering step. Character tags (like takamachi_nanoha) identify specific named characters; general tags (like 1girl, red_hair, blue_eyes, school_uniform) describe visual attributes. The script writes both categories into the .txt caption file, but only general tags are used for the visual-attribute filter shown above. This separation lets you either filter by a known character tag (for older, popular characters) or by a combination of visual attributes (for new or less-popular characters where the character tag does not exist in the model's vocabulary). The 0.5 probability threshold is the article author's convention — the library exposes no default.
Filter for one character
The source article's author emphasizes that the resulting tags will not be perfect, but they will be good enough for training. Manual inspection of the tagged folder before pruning is a worthwhile step — it lets you calibrate which tags reliably identify your character and which are noise.
Booru tags make filtering straightforward. For a red-haired female character (from article 218):
if "1girl" in gen_tags and "1boy" not in gen_tags and "red_hair" in gen_tags:
copy_image_and_tags(frame, output_dir, activation_tag="my_character")
For characters that existed before November 2021, you can match the character tag directly (e.g., takamachi_nanoha in tags_char). Success depends on whether the character appears in the training data.
The source article recommends spending about half an hour on this pruning step. The workflow is straightforward: open an image viewer, advance through the folder, and delete frames that fall into any of the categories above. The key question for each frame is: does this image clearly show my character alone, at a reasonable quality, with no distracting visual elements? When in doubt, delete it — a tighter dataset trains a more consistent LoRA.
Manual prune to 20–50 images
Automation gets you close; human review gets you quality. Open the output folder in an image viewer and delete:
| Category | What to look for | Why it hurts |
|---|---|---|
| Wrong character | Tag match but visual mismatch | Pollutes the concept |
| Multiple characters | Extra arms, background figures | Dilutes the target |
| Duplicate sequences | Near-identical consecutive frames from dialogue | Reduces diversity |
| OP/ED frames | Recurring credit sequences across episodes | Repeated identical images |
| Tweens (in-betweens) | Motion blur, off-model faces, awkward poses | Not representative |
| Low quality | Distant shots, bad linework, compression artifacts | Trains noise |
This pruning checklist comes directly from article 218. The target of 20–50 images is a community convention; no single authoritative source prescribes it.
Path B: Synthetic dataset with ChatGPT Plus / DALL-E 3
Prompt template
Craft a base prompt with a [SUBJECT] placeholder (from article 3327):
Photo of a delicious-looking cinnamon-bun [SUBJECT]. The entire aircraft is
constructed from fresh, golden-brown cinnamon bun material, with swirls of
cinnamon and icing visible.
Feed ChatGPT a subject list of 30+ items and instruct it to generate images per subject, replacing [SUBJECT] each time.
Friction points (Jun 2024 snapshot)
| Symptom | Cause | Workaround |
|---|---|---|
| Only 1 image per subject | Per-request limit changed (was 4, then 2, then 1, per single-source report) | Re-prompt or repeat the list; sort files manually |
| Grid/collage output | Model returns a single image containing all 4 | Rephrase: "generate 4 separate images" or regenerate |
| Traffic cooldown | Per-session limit based on server load (single-source report) | Wait the stated cooldown; sometimes resumes early |
| Long filenames | Prompt embedded in filename | Batch-rename script (drag-drop Tkinter GUI provided in source) |
The 4→2→1 progression and the traffic-based cooldown are single-source observations from article 3327. OpenAI does not publish these numbers. As of July 2026, actual limits may differ.
Rename at scale
The source article includes a tkinterdnd2 drag-and-drop renamer that converts long DALL-E filenames to foldername_001.png, foldername_002.png, etc., with undo support.
Captioning: what the sources don't cover
Neither article uses an LLM to write captions for existing images. DeepDanbooru emits tags, not natural-language captions. ChatGPT is used only for generation, not for vision-to-text captioning. For descriptive captions, you need a separate vision-language model (BLIP-2, LLaVA, GPT-4V) — outside the scope of these guides.
Common errors and fixes
| Error / Symptom | Likely cause | Fix |
|---|---|---|
ffmpeg: command not found | ffmpeg not on PATH | Install ffmpeg; add to PATH |
ModuleNotFoundError: deepdanbooru | Package not installed | pip install git+https://github.com/KichangKim/DeepDanbooru.git |
tensorflow import fails | Version mismatch | Match version in requirements.txt (listed as ≥2.17.0 on repo main) |
| Zero tags written | Threshold too high or tag files missing | Lower threshold; verify tag files exist |
| ChatGPT returns one image instead of four | Per-request limit changed | Re-prompt |
| ChatGPT returns a 2×2 grid | Model interprets request as a collage | Forbid grids in the prompt |
| Rename script crashes | Windows 260-char path limit | Enable long paths or use a short path |
FAQ
How do you automatically create a LoRA training dataset from anime? Extract I-frames with ffmpeg -vf select=eq(pict_type\,I), auto-tag with DeepDanbooru, filter by character tags, copy matches to a new folder, then prune to 20–50 diverse images.
How many images do you need for a LoRA? Community practice targets 20–50 curated images. Fewer risks underfitting; more adds diminishing returns. No official trainer documentation specifies a hard number.
Can you use ChatGPT to generate LoRA training data? Yes. With ChatGPT Plus, use a prompt template with a [SUBJECT] placeholder, feed a subject list, and request images per subject. Download, batch-rename, and curate.
What tools tag anime images automatically? DeepDanbooru (TensorFlow, Danbooru 2021 training data) outputs Booru tags to .txt files. WD1.4 Tagger (used in Kohya-ss, A1111) is another option.
How do you extract keyframes from anime for training? Use ffmpeg -i input.mkv -vf "select=eq(pict_type\,I)" -vsync vfr "out-%06d.png". I-frames are full frames at scene changes and regular GOP intervals; anime scene changes often align with animation keyframes.
Internal links
- LoRA training hyperparameters guide
- DeepDanbooru vs WD1.4 Tagger comparison
- Anime video preprocessing for ML datasets
Images to create
Sources
| Source | What it contributes |
|---|---|
| Civitai article 218 | Keyframe extraction workflow, DeepDanbooru tagging scripts, character filtering logic, pruning checklist |
| Civitai article 3327 | ChatGPT Plus / DALL-E 3 dataset generation workflow, rename script, friction-point observations |
| DeepDanbooru GitHub repo | API documentation, project structure, requirements, README |
| DeepDanbooru release v3-20211112-sgd-e28 | Model training date, optimizer, dataset version |
| project.py source | load_model_from_project, load_tags_from_project function signatures |
| data/__init__.py source | load_image_for_evaluate signature and normalization behavior |
| data/dataset.py source | load_tags implementation |
| Stack Overflow — ffmpeg keyframe extraction | select=eq(pict_type,I) syntax confirmation |