少女祈祷中...

成品模型效果展示

  • 什么时候需要这类模型?
1
希望对出图内容的某一内容进行修改而不过多的改变其他内容时,推荐使用该类模型。
pony contrast adjuster
pony contrast adjuster
https://civitai.com/models/536749/pony-contrast-adjuster
Illustrious lineart adjuster
Illustrious lineart adjuster
https://civitai.com/models/1009332/illustrious-lineart-adjuster
Illustrious Auto Nude
Illustrious Auto Nude
https://civitai.com/models/1043351/illustrious-auto-nude

训练方法

数据集

准备合适数量、样式分布较广且平均(单一类型的反面)的图片,需要打标。数量根据自己的算力和修改图片的耗费决定,条件允许的情况下越多越准确。我这里以通过HakuBooru收集到的各种评级的图片为例,每种评级16张,共64张图片:

训练原始底模

以这些图片作为原始图片,正常训练出一个模型作为一个原始底模,以下是在lora-scripts中的训练参数参考,将模型训练至拟合即可:

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
model_train_type = "sdxl-lora"
pretrained_model_name_or_path = "D:/hmkai/ComfyUI/models/checkpoints/llustrious-XL-v0.1.safetensors"
train_data_dir = "D:/data/差异/原始图片64"
prior_loss_weight = 1
resolution = "1024,1024"
enable_bucket = true
min_bucket_reso = 256
max_bucket_reso = 2048
bucket_reso_steps = 32
bucket_no_upscale = true
output_name = "IL-64-MKI"
output_dir = "./output"
save_model_as = "safetensors"
save_precision = "fp16"
save_every_n_epochs = 5
max_train_epochs = 50
train_batch_size = 4
gradient_checkpointing = true
gradient_accumulation_steps = 16
network_train_unet_only = true
network_train_text_encoder_only = false
learning_rate = 0.0001
unet_lr = 0.0001
text_encoder_lr = 0.00001
lr_scheduler = "cosine_with_restarts"
lr_warmup_steps = 0
lr_scheduler_num_cycles = 1
optimizer_type = "Lion8bit"
network_module = "networks.lora"
network_dim = 1 # 通常dim越大对画面修改越大
network_alpha = 1
log_with = "tensorboard"
logging_dir = "./logs"
caption_extension = ".txt"
shuffle_caption = false
keep_tokens = 0
max_token_length = 255
seed = 2104
mixed_precision = "bf16"
fp8_base = false
sdpa = true
lowram = false
cache_latents = true
cache_latents_to_disk = false
cache_text_encoder_outputs = false
cache_text_encoder_outputs_to_disk = false
persistent_data_loader_workers = true

制作差异图片

接着我们要做差异,也就是对这些图片进行一些修改

常见的修改比如一些 线稿加深,对比度加强,面部美颜,胸部大小,星星眼等等…总之如果你想改变单一内容而且尽量保证其他内容不变时,推荐采用差异炼丹

根据你希望的“差异”,为每一张图片都制作一份差异后的图片,图片的标签不变

我这里以对比度为例(其实我很想做胸部调节和星星眼之类的局部差异丹,但是我的PS水平并不好),修改后的数据集:

image

训练差异模型

以修改后的图片作为训练集,在lora-scripts中,对于上方原始的训练参数,你只需要且最好仅改变以下内容:

1
2
3
4
train_data_dir = "D:/data/差异/原始图片64" # 填写你修改后的训练集
output_name = "IL-lineart-MKI" # 改一下输出模型的名称
base_weights = [ "D:\\hmkai\\lora-scripts\\output\\IL-64-MKI.safetensors" ] # 填写你上面炼制的LoRA模型路径
base_weights_multiplier = [ 1 ]

其中base_weights的作用是将原先炼制的LoRA融合到底模,假如你的脚本中没有这一项,请使用一些方法先融合LoRA模型至底模中,炼制差异模型时将原先的底模替换为融合后的模型

等待训练完成后即可获得一个只改变某单一内容的LoRA啦☆(<ゝω・)~Kira☆~