https://github.com/kohya-ss/sd-scripts

Config Start

config: seems like the epoch calculation is wrong, when in doubt just set the number low and set repeats high by renaming folders.

having multiple epochs is similar to having multiple repeats, but ending epochs is slow

$run = $True
$ckpt = "<CHANGE ME>"; # base checkpoint to finetune

$vae = "<CHANGE ME>"
$img_dir = "<CHANGE ME>";

my_concepts_folder

12_A, images in A will repeat 12x

20_B, images in B will repeat 20x

$reg_dir = "<CHANGE ME>"; #optional, just point this to an empty folder if you don't care.
$output = "<CHANGE ME>"; # safetensors output folder

$output_name="<change me>_locon"
$noise_offset=0
$keep_tokens=0
$learning_rate=<change me>
$text_encoder_lr=<change me>
$unet_lr=<change me>
$lr_warmup_ratio = 0.1
$resolution=512
$train_batch_size = 4
$num_epochs = 5
$save_every_n_epochs=1
$scheduler="cosine_with_restarts"
$network_dim=4 # linear layers
$network_alpha=4 # linear layers
$conv_dim=1
$conv_alpha=1 # not used right now cause i'm too dumb to pass in nargs through accelerate call for python
$network_args="conv_dim={0}" -f $conv_dim

Config End

Clear-Host

if (Test-Path -Path $output) {
Write-Output "Output folder {$output} already exists."
} else {
Write-Output "Creating output folder {$output}"
mkdir -p $output
}

Write-Output "Measuring folders:"
$total = 0
$folders = Get-ChildItem -Path $img_dir -Directory
$folders | ForEach-Object {
$parts = $.Name.Split("")
if(($parts | Measure-Object | ForEach-Object{$.Count}) -ne 2)
{
Return
}
$repeats = [int]$parts[0]
$imgs = Get-ChildItem $
.FullName -Recurse -File -Include .png, .bmp, .gif, .jpg,.jpeg, .webp | Measure-Object | ForEach-Object{$_.Count}
$img_repeats = ($repeats * $imgs)
Write-Output "`t$($parts[1]): $repeats repeats * $imgs images = $($img_repeats)"
$total += $img_repeats
}
Write-Output "Total images with repeats: $total"
$mts = int
Write-Output "Max training steps $total / $train_batch_size * $num_epochs = $mts"
$lr_warmup_steps = [math]::Round($mts * $lr_warmup_ratio)
Write-Output "Warmup steps: $lr_warmup_steps, Batch size: $train_batch_size, Epochs: $num_epochs"

if ($run) {
.\venv\Scripts\activate

accelerate launch --num_cpu_threads_per_process 12 train_network.py `
    --network_module="locon.locon_kohya" `
    --network_args=$network_args `
    --pretrained_model_name_or_path=$ckpt `
    --train_data_dir=$img_dir `
    --reg_data_dir=$reg_dir `
    --output_dir=$output `
    --logging_dir=$output `
    --caption_extension=".txt" `
    --shuffle_caption `
    --keep_tokens=$keep_tokens `
    --prior_loss_weight=1 `
    --resolution=$resolution,$resolution `
    --enable_bucket `
    --min_bucket_reso=320 `
    --max_bucket_reso=960 `
    --train_batch_size=$train_batch_size `
    --learning_rate=$learning_rate `
    --unet_lr=$unet_lr `
    --text_encoder_lr=$text_encoder_lr  `
    --lr_scheduler_num_cycles=$num_epochs `
    --max_train_steps=$mts `
    --mixed_precision="fp16" `
    --save_precision="fp16" `
    --xformers `
    --save_every_n_epochs=$save_every_n_epochs `
    --save_model_as=safetensors `
    --clip_skip=2 `
    --seed=22 `
    --network_dim=$network_dim `
    --network_alpha=$network_alpha `
    --max_token_length=150 `
    --cache_latents `
    --lr_scheduler=$scheduler `
    --vae=$vae `
    --lr_warmup_steps=$lr_warmup_steps `
    --noise_offset=$noise_offset `
    --training_comment="" `
    --caption_dropout_rate=0.0 `
    --persistent_data_loader_workers `
    --output_name=$output_name `

}

Edit Report
Pub: 01 Mar 2023 02:32 UTC
Views: 58