ArtificialGuyBR

Home / Blog / Training LoRAs

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.

8 sources cited Training LoRAs

Automated LoRA Dataset Creation: Extract, Filter, Tag, QA

TL;DR


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:

  1. Video → frames → tags → filter → prune — turn an anime series into a character-specific dataset.
  2. 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

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:

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:

CategoryWhat to look forWhy it hurts
Wrong characterTag match but visual mismatchPollutes the concept
Multiple charactersExtra arms, background figuresDilutes the target
Duplicate sequencesNear-identical consecutive frames from dialogueReduces diversity
OP/ED framesRecurring credit sequences across episodesRepeated identical images
Tweens (in-betweens)Motion blur, off-model faces, awkward posesNot representative
Low qualityDistant shots, bad linework, compression artifactsTrains 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)

SymptomCauseWorkaround
Only 1 image per subjectPer-request limit changed (was 4, then 2, then 1, per single-source report)Re-prompt or repeat the list; sort files manually
Grid/collage outputModel returns a single image containing all 4Rephrase: "generate 4 separate images" or regenerate
Traffic cooldownPer-session limit based on server load (single-source report)Wait the stated cooldown; sometimes resumes early
Long filenamesPrompt embedded in filenameBatch-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 / SymptomLikely causeFix
ffmpeg: command not foundffmpeg not on PATHInstall ffmpeg; add to PATH
ModuleNotFoundError: deepdanbooruPackage not installedpip install git+https://github.com/KichangKim/DeepDanbooru.git
tensorflow import failsVersion mismatchMatch version in requirements.txt (listed as ≥2.17.0 on repo main)
Zero tags writtenThreshold too high or tag files missingLower threshold; verify tag files exist
ChatGPT returns one image instead of fourPer-request limit changedRe-prompt
ChatGPT returns a 2×2 gridModel interprets request as a collageForbid grids in the prompt
Rename script crashesWindows 260-char path limitEnable 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.



Images to create


Sources

SourceWhat it contributes
Civitai article 218Keyframe extraction workflow, DeepDanbooru tagging scripts, character filtering logic, pruning checklist
Civitai article 3327ChatGPT Plus / DALL-E 3 dataset generation workflow, rename script, friction-point observations
DeepDanbooru GitHub repoAPI documentation, project structure, requirements, README
DeepDanbooru release v3-20211112-sgd-e28Model training date, optimizer, dataset version
project.py sourceload_model_from_project, load_tags_from_project function signatures
data/__init__.py sourceload_image_for_evaluate signature and normalization behavior
data/dataset.py sourceload_tags implementation
Stack Overflow — ffmpeg keyframe extractionselect=eq(pict_type,I) syntax confirmation