Sign In

[Tutorial] Characterpack Training with Civitai Trainer Including Helper Scripts

[Tutorial] Characterpack Training with Civitai Trainer Including Helper Scripts

Civitai Trainer: Workflow for Character Pack Training Using the Helper Scripts

These scripts are designed to simplify the creation and management of datasets for training character packs in the Civitai Trainer. Follow the steps below for an efficient workflow:


1. Preparing the Dataset

  1. Create a Base Folder:

    • Set up a folder containing subfolders, where each subfolder represents a specific character.

    • Important: Each subfolder should:

      • Contain images showing only that character.

      • Include diverse angles and poses (front, back, side, action poses, etc.).

      • Exclude blurry, unclear, or low-quality images.

  2. Image Count Recommendation:

    • Aim for around 50 images per character.

    • If fewer images are available, you can start with at least 20, but the quality and diversity of images are critical.


2. Harmonizing the Dataset

  1. Run the Harmony Script:

    • Use this script on the base folder containing all character subfolders.

    • What It Does:

      • Converts all images to a consistent PNG format.

      • Renames files in a clean and systematic way: FolderName001.png, FolderName002.png, etc.

      • Removes original files if they’re not in PNG format.

  2. Result:

    • A clean, harmonized dataset where all images are uniform in format and naming, making it easier to manage and upload.


3. Creating Sidecar Files

  1. Run the Sidecar Script:

    • Apply this script to the harmonized dataset.

    • What It Does:

      • Generates .txt sidecar files for each image.

      • The trigger word in the sidecar file is automatically set to the folder name.

  2. Customizing the Trigger Word:

    • If you want a specific trigger for a character, rename the corresponding folder before running the script.

    • Example: If your folder is named DragonKnight, the trigger for all images in that folder will be DragonKnight.


4. Uploading to Civitai Trainer

  1. Compress the Dataset:

    • Zip the entire dataset (base folder with subfolders, images, and sidecars).

  2. Upload to the Civitai Trainer:

    • Select Type: Character.

    • Enter the Name: Choose something relevant to the anime/theme, e.g., FantasyKnights.

  3. Auto Label Configuration:

    • Existing Tags: Set to Append (this prevents overriding and instead adds tags).

    • Max Tags: 20

    • Min Threshold: 0.4

    • Leave "Blacklist," "Prepend Tags," and "Append Tags" fields empty.

  4. Fine-Tune Tags:

    • After auto-labeling, review and adjust the dataset.

    • Recommended to Remove: Tags like backgrounds, indoor, outdoor, objects, solo/solo focus—anything irrelevant to the character’s focus.

    • Keep tags that describe the character’s appearance, features, and accessories.

  5. Download the Finalized Dataset:

    • Save the processed dataset for future use.

    • This step ensures you have a local backup and a clean dataset ready for re-upload or reuse.


5. Reorganizing the Dataset

  1. Unpack the Finalized Dataset:

    • After downloading the dataset, all files (images and sidecars) will likely be in one folder.

  2. Run the ImageSorter Script:

    • Use this script to reorganize the files based on their triggers.

    • What It Does:

      • Reads the trigger word from the sidecar files.

      • Recreates the original folder structure by grouping images and their corresponding sidecars.

  3. Result:

    • A fully organized dataset where each character has its own folder with associated images and sidecars.


6. Training Recommendations

  1. Model Settings:

    • Model Type: Use Pony (or your preferred base model).

    • Leave other settings at their default.

  2. Training Configuration:

    • Steps: Around 1000 (adjust based on dataset size and complexity).

    • Shuffle Tags: Enable for better variation during training.

    • Keep Token: Set to 3.


Additional Tips

  • Dataset Quality: Prioritize image quality and diversity. The more representative the images are of your character’s appearance and poses, the better the training result.

  • Backup Your Work: Always save copies of your harmonized dataset and processed sidecars before uploading. This avoids needing to redo work in case of errors or loss.

  • Experiment and Adjust: Training can vary based on the dataset size, model, and configuration. Feel free to tweak parameters and iterate for optimal results.


Feel free to reach out if you have any questions or need further clarification. Happy training!


Script Description:


1. harmony.py - Image Preparation and Harmonization

This script processes images within a given folder structure to standardize their format and naming convention.

  • Key Functionality:

    1. Scan Subfolders: It iterates through all subfolders in the specified base folder.

    2. Format Conversion: Images are converted to PNG format for consistency.

    3. Renaming: Each image is renamed sequentially with a prefix matching its parent folder name and a padded numeric suffix (e.g., Folder001.png).

    4. Cleanup: If the original image isn't in PNG format, it gets deleted after conversion.

  • Use Case: Ideal for preparing image datasets by harmonizing their format and naming before further processing or training.


2. sidecarcreate.py - Sidecar File Creation

This script generates sidecar .txt files for images in a directory, using the folder name as a tag.

  • Key Functionality:

    1. Identify Images: It detects image files in the specified directory and its subfolders.

    2. Create Sidecars: For each image, a corresponding .txt file is created with the image's base name. The sidecar file contains the name of the folder where the image resides.

    3. Tagging: The folder name is used as a tag in the sidecar file to help identify and classify images later.

  • Use Case: Useful for creating metadata files needed during the training of machine learning models, where tags or triggers are required for classification.


3. imagesort.py - Image and Sidecar File Sorter

This script organizes images and their corresponding sidecar files based on a "trigger" tag found in the sidecar files.

  • Key Functionality:

    1. Trigger Extraction: Reads the first tag from the .txt sidecar file (separated by commas).

    2. Directory Creation: Creates a subdirectory in the target folder corresponding to the extracted trigger.

    3. File Sorting: Moves the image and its sidecar file into the appropriate trigger folder.

    4. Automation: Ensures that files are grouped based on tags, making it easier to manage large datasets.

  • Use Case: Particularly helpful after training or dataset generation when platforms like Civitai combine all images and sidecar files into a single folder, making reorganization necessary.


Summary: These scripts streamline the preparation, tagging, and sorting of image datasets for tasks like machine learning model training. They ensure a structured workflow by harmonizing file formats, creating metadata files, and organizing files based on classification tags.



Update:

Script harmony had a little bug. Fixed it.

16

Comments