|
|
|
|
|
|
|
$pretrained_model_name_or_path = "D:\models\v1-5-pruned-mse-vae.ckpt" |
|
$train_dir = "D:\models\blakecreates" |
|
$output_dir = "D:\models\blakecreates\diffusers_fine_tuned_model_bucket" |
|
$training_folder = "dataset\192_cables retake artstyle" |
|
|
|
$learning_rate = 1e-6 |
|
$dataset_repeats = 192 |
|
$train_batch_size = 4 |
|
$epoch = 1 |
|
$save_every_n_epochs=1 |
|
$mixed_precision="fp16" |
|
$num_cpu_threads_per_process=6 |
|
$lr_scheduler="constant" |
|
|
|
$max_resolution = "576,704" |
|
|
|
|
|
$data_dir = $train_dir + "\" + $training_folder |
|
|
|
$shellApp = New-Object -ComObject 'shell.application' |
|
$folderNamespace = $shellApp.Namespace($data_dir) |
|
$get_smalest_resolution = Get-ChildItem $data_dir -Recurse -File -Include *.png, *.jpg, *.webp | |
|
ForEach-Object { |
|
$image = $folderNamespace.ParseName($_.Name) |
|
|
|
if ($folderNamespace.GetDetailsOf($image, 31) -match '(?<width>\d+) x (?<height>\d+)') { |
|
[PsCustomObject]@{ |
|
Image = $_.FullName |
|
Width = $Matches.width |
|
Height = $Matches.height |
|
PixelResolution = [int]($Matches.width) * [int]($Matches.height) |
|
|
|
} |
|
} |
|
} | Sort-Object -Property PixelResolution | Select-Object -first 1 |
|
|
|
$width, $height = $max_resolution -split "," |
|
|
|
if (([int]$width * [int]$height) -gt $get_smalest_resolution.PixelResolution) { |
|
|
|
$smalest_resolution = $get_smalest_resolution.Width + "," + $get_smalest_resolution.Height |
|
Write-Output "Smallest resolution of images data found is " $get_smalest_resolution.Image "at $smalest_resolution. Replace image with a larger one, or change resolution to prevent this resolution change." |
|
|
|
$max_resolution = $smalest_resolution |
|
} |
|
|
|
|
|
$ErrorActionPreference = "Stop" |
|
|
|
|
|
cd D:\kohya_ss |
|
.\venv\Scripts\activate |
|
|
|
|
|
python D:\kohya_ss\diffusers_fine_tuning\merge_captions_to_metadata.py ` |
|
--caption_extention ".caption" $train_dir"\"$training_folder $train_dir"\meta_cap.json" |
|
|
|
|
|
python D:\kohya_ss\diffusers_fine_tuning\prepare_buckets_latents.py ` |
|
$train_dir"\"$training_folder ` |
|
$train_dir"\meta_cap.json" ` |
|
$train_dir"\meta_lat.json" ` |
|
$pretrained_model_name_or_path ` |
|
--batch_size 4 --max_resolution $max_resolution --mixed_precision fp16 |
|
|
|
|
|
$image_num = Get-ChildItem "$train_dir\$training_folder" -Recurse -File -Include *.npz | Measure-Object | %{$_.Count} |
|
$repeats = $image_num * $dataset_repeats |
|
|
|
|
|
$max_train_set = [Math]::Ceiling($repeats / $train_batch_size * $epoch) |
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process $num_cpu_threads_per_process D:\kohya_ss\diffusers_fine_tuning\fine_tune.py ` |
|
--pretrained_model_name_or_path=$pretrained_model_name_or_path ` |
|
--in_json $train_dir"\meta_lat.json" ` |
|
--train_data_dir=$train_dir"\"$training_folder ` |
|
--output_dir=$output_dir ` |
|
--train_batch_size=$train_batch_size ` |
|
--dataset_repeats=$dataset_repeats ` |
|
--learning_rate=$learning_rate ` |
|
--max_train_steps=$max_train_set ` |
|
--use_8bit_adam --xformers ` |
|
--mixed_precision=$mixed_precision ` |
|
--save_every_n_epochs=$save_every_n_epochs ` |
|
--lr_scheduler=$lr_scheduler ` |
|
--seed=494481440 ` |
|
--train_text_encoder ` |
|
--save_precision="fp16" |
|
|