使用的软件平台是:sd-scripts
【检查目录下图片分辨率】
【找寻特定分辨率的图片】
【图片打标】
【图片打标,使用GeminiAPI】
【常用标签】
【常用标签,筛选】
【tag
去重复】
【尝试让ai优化txt里的tag】
【图片缩放】
【图片尺寸修正】
安装
1 2 3 4 5 6 7 8 9 10
| git clone https://github.com/kohya-ss/sd-scripts.git cd sd-scripts
python -m venv venv .\venv\Scripts\activate
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124 pip install --upgrade -r requirements.txt
accelerate config
|
数据集配置文件 (config.toml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| [general] enable_bucket = true # 是否使用Aspect Ratio Bucketing
[[datasets]] resolution = [768, 768] # 训练分辨率 batch_size = 1 # 批次大小
[[datasets.subsets]] image_dir = 'E:\AI\01' # 指定包含训练图像的文件夹 caption_extension = '.txt' # 若使用txt文件,更改此项 num_repeats = 6 # 训练图像的重复次数 flip_aug = true #翻转增强 shuffle_caption = true # 随机字幕 keep_tokens = 1 caption_dropout_rate = 0.1 #字幕丢失率
[[datasets.subsets]] image_dir = 'E:\AI\02' # 指定包含训练图像的文件夹 caption_extension = '.txt' # 若使用txt文件,更改此项 num_repeats = 6 # 训练图像的重复次数
|
数据集配置
| 参数 |
值 |
说明 |
| image_dir |
“E:\01” |
图片目录 |
| image_count |
11 |
|
| num_repeats |
6 |
每张图片重复次数 |
| shuffle_caption |
False |
|
| keep_tokens |
0 |
|
| keep_tokens_separator |
|
|
| caption_separator |
, |
|
| secondary_separator |
None |
|
| enable_wildcard |
False |
|
| caption_dropout_rate |
0.0 |
|
| caption_dropout_every_n_epoches |
0 |
|
| caption_tag_dropout_rate |
0.0 |
|
| caption_prefix |
None |
|
| caption_suffix |
None |
|
| color_aug |
False |
|
| flip_aug |
True |
图片翻转增强 |
| face_crop_aug_range |
None |
|
| random_crop |
False |
|
| token_warmup_min |
1 |
|
| token_warmup_step |
0 |
|
| alpha_mask |
False |
|
| is_reg |
False |
|
| class_tokens |
None |
|
| caption_extension |
.txt |
标签文件后缀 |
卷积层
LoRA-LierLa
(用于 Li n e a r La yers 的 LoRA,读作 “Liela”)。 (默认)
适用于 Linear 和卷积层 Conv2d 的 1x1 Kernel 的 LoRA
LoRA-C3Lier
(用于具有 3x3 Kernel 的卷积层和 Li n e a r 层的 LoRA,读作
“Seria”)
适用于 3x3 Kernel 的 Conv2d 的 LoRA
与 LoRA-LierLa 相比,LoRA-C3Lier
可能会获得更高的准确性,因为它适用于更多的层。
使用LoRA-C3Lier
1 2
| --network_args "conv_dim=4" --network_args "conv_dim=32" "conv_alpha=16"
|
SDXL 训练脚本示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| accelerate launch --num_cpu_threads_per_process 1 sdxl_train_network.py
# 00 --pretrained_model_name_or_path="G:\AI\ComfyUI_windows_portable\ComfyUI\models\checkpoints\pony\waiREALCN_v130.safetensors"
# 01 --save_model_as=safetensors --output_dir="E:\AI\XunLian\lora"
# 02 --prior_loss_weight=1.0
# 03 --gradient_checkpointing --persistent_data_loader_workers
# 04 --network_module=networks.lora
# 05 --sdpa --mixed_precision="bf16"
# 06 --cache_text_encoder_outputs --cache_latents --network_train_unet_only
# 07 --sample_prompts="E:\AI\TiShiCi.txt" --sample_sampler="euler_a" --logging_dir="E:\AI\log"
# 08 --no_half_vae
# 09 --network_dim=64 --network_alpha=32
# 10 --scale_weight_norms=1 --network_dropout=0 --noise_offset=0.1
# 11 --max_bucket_reso=768 --bucket_reso_steps=64
# 12 --gradient_accumulation_steps=5 --max_train_epochs=4
# 13 --optimizer_type="AdamW8bit" --lr_scheduler="cosine" --learning_rate=5e-5 --unet_lr=5e-5
# 14 --output_name="SDXL_pony_610" --log_prefix="SDXL_pony_610"
# 15 --max_grad_norm=1.0 --max_data_loader_n_workers=1 --vae_batch_size=5 --cache_latents_to_disk --bucket_no_upscale --full_bf16
# 16 --multires_noise_iterations 6 --multires_noise_discount 0.3
# 17 --loss_type huber --huber_schedule snr --huber_c 0.1
# 18 --lr_warmup_steps=100
# 19 --network_args "down_lr_weight=1, 1, 1, 1, 1, 1, 1, 1, 1" "mid_lr_weight=1, 0.8, 0.5" "up_lr_weight=0, 0, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4"
# 20 --save_every_n_steps=200 --save_precision="bf16" --dataset_config="E:\AI\PeiZhi_01.toml"
|