cyburn commited on
Commit
e593b16
1 Parent(s): 4a11ef4

1st commit

Browse files
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: unknown
3
+ ---
4
+ # Cables Retake finetuned style Model
5
+
6
+ Produced from publicly available pictures in 576x704 format.
7
+
8
+ Two models available. One trained using kohya_ss train_db script and the other one using diffusers_fine_tuning sctipt.
9
+
10
+ ## Using the model
11
+
12
+ * common subject prompt tokens: `cables retake artstyle <wathever>`
13
+
14
+ ## Example prompts
15
+
16
+ `cables retake artstyle smiling woman`:
cables_retake_artstyle-kohys_ss-diffusers.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:738f5674e11e137051c8c3e9ce7e69f57f240e3f1ed4cade98338140bc885b76
3
+ size 2132856686
cables_retake_artstyle-kohys_ss-train_db.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0390e00e65242c87fd8d86fac60244c522b94ae7c92e8254d34e746469119683
3
+ size 2132856686
caption.ps1 ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This powershell script will create a text file for each files in the folder
2
+ #
3
+ # Usefull to create base caption that will be augmented on a per image basis
4
+
5
+ $folder = "D:\models\dariusz_zawadzki\subset_bucket\"
6
+ $file_pattern="*.*"
7
+ $caption_text="radius kawazaki artstyle"
8
+
9
+ $files = Get-ChildItem $folder$file_pattern -Include *.png, *.jpg, *.webp -File
10
+ foreach ($file in $files) {
11
+ if (-not(Test-Path -Path $folder\"$($file.BaseName).txt" -PathType Leaf)) {
12
+ New-Item -ItemType file -Path $folder -Name "$($file.BaseName).txt" -Value $caption_text
13
+ }
14
+ }
kohya_diffusers_fine_tuning.ps1 ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Sylvia Ritter. AKA: by silvery trait
2
+
3
+ # variable values
4
+ $pretrained_model_name_or_path = "D:\models\v1-5-pruned-mse-vae.ckpt"
5
+ $train_dir = "D:\models\blakecreates"
6
+ $output_dir = "D:\models\blakecreates\diffusers_fine_tuned_model_bucket"
7
+ $training_folder = "dataset\192_cables retake artstyle"
8
+
9
+ $learning_rate = 1e-6
10
+ $dataset_repeats = 192
11
+ $train_batch_size = 4
12
+ $epoch = 1
13
+ $save_every_n_epochs=1
14
+ $mixed_precision="fp16"
15
+ $num_cpu_threads_per_process=6
16
+ $lr_scheduler="constant"
17
+
18
+ $max_resolution = "576,704"
19
+
20
+ # You should not have to change values past this point
21
+ $data_dir = $train_dir + "\" + $training_folder
22
+ # Get smalest image resolution to prevent upscaling to that
23
+ $shellApp = New-Object -ComObject 'shell.application'
24
+ $folderNamespace = $shellApp.Namespace($data_dir)
25
+ $get_smalest_resolution = Get-ChildItem $data_dir -Recurse -File -Include *.png, *.jpg, *.webp |
26
+ ForEach-Object {
27
+ $image = $folderNamespace.ParseName($_.Name)
28
+
29
+ if ($folderNamespace.GetDetailsOf($image, 31) -match '(?<width>\d+) x (?<height>\d+)') {
30
+ [PsCustomObject]@{
31
+ Image = $_.FullName
32
+ Width = $Matches.width
33
+ Height = $Matches.height
34
+ PixelResolution = [int]($Matches.width) * [int]($Matches.height)
35
+ # IsPortrait = $([int]$Matches.height -gt [int]$Matches.width)
36
+ }
37
+ }
38
+ } | Sort-Object -Property PixelResolution | Select-Object -first 1
39
+
40
+ $width, $height = $max_resolution -split ","
41
+
42
+ if (([int]$width * [int]$height) -gt $get_smalest_resolution.PixelResolution) {
43
+
44
+ $smalest_resolution = $get_smalest_resolution.Width + "," + $get_smalest_resolution.Height
45
+ 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."
46
+
47
+ $max_resolution = $smalest_resolution
48
+ }
49
+
50
+ # stop script on error
51
+ $ErrorActionPreference = "Stop"
52
+
53
+ # activate venv
54
+ cd D:\kohya_ss
55
+ .\venv\Scripts\activate
56
+
57
+ # create caption json file
58
+ python D:\kohya_ss\diffusers_fine_tuning\merge_captions_to_metadata.py `
59
+ --caption_extention ".caption" $train_dir"\"$training_folder $train_dir"\meta_cap.json"
60
+
61
+ # create images buckets
62
+ python D:\kohya_ss\diffusers_fine_tuning\prepare_buckets_latents.py `
63
+ $train_dir"\"$training_folder `
64
+ $train_dir"\meta_cap.json" `
65
+ $train_dir"\meta_lat.json" `
66
+ $pretrained_model_name_or_path `
67
+ --batch_size 4 --max_resolution $max_resolution --mixed_precision fp16
68
+
69
+ # Get number of valid images
70
+ $image_num = Get-ChildItem "$train_dir\$training_folder" -Recurse -File -Include *.npz | Measure-Object | %{$_.Count}
71
+ $repeats = $image_num * $dataset_repeats
72
+
73
+ # calculate max_train_set
74
+ $max_train_set = [Math]::Ceiling($repeats / $train_batch_size * $epoch)
75
+
76
+
77
+ accelerate launch --num_cpu_threads_per_process $num_cpu_threads_per_process D:\kohya_ss\diffusers_fine_tuning\fine_tune.py `
78
+ --pretrained_model_name_or_path=$pretrained_model_name_or_path `
79
+ --in_json $train_dir"\meta_lat.json" `
80
+ --train_data_dir=$train_dir"\"$training_folder `
81
+ --output_dir=$output_dir `
82
+ --train_batch_size=$train_batch_size `
83
+ --dataset_repeats=$dataset_repeats `
84
+ --learning_rate=$learning_rate `
85
+ --max_train_steps=$max_train_set `
86
+ --use_8bit_adam --xformers `
87
+ --mixed_precision=$mixed_precision `
88
+ --save_every_n_epochs=$save_every_n_epochs `
89
+ --lr_scheduler=$lr_scheduler `
90
+ --seed=494481440 `
91
+ --train_text_encoder `
92
+ --save_precision="fp16"
kohya_train_db_fixed_reg.ps1 ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This powershell script will create a model using the fine tuning dreambooth method. It will require landscape,
2
+ # portrait and square images.
3
+ #
4
+ # Adjust the script to your own needs
5
+
6
+ # variable values
7
+ $pretrained_model_name_or_path = "D:\models\v1-5-pruned-mse-vae.ckpt"
8
+ $data_dir = "D:\models\blakecreates\dataset"
9
+ $reg_data_dir = "D:\models\blakecreates\reg"
10
+ $logging_dir = "D:\models\blakecreates\logs"
11
+ $output_dir = "D:\models\blakecreates\train_db_fixed_model_reg"
12
+ $resolution = "576,704"
13
+ $lr_scheduler="constant"
14
+
15
+ $image_num = Get-ChildItem $data_dir -Recurse -File -Include *.png, *.jpg, *.webp | Measure-Object | %{$_.Count}
16
+
17
+ Write-Output "image_num: $image_num"
18
+
19
+ $dataset_repeats = 64
20
+ $learning_rate = 1e-6
21
+ $train_batch_size = 4
22
+ $epoch = 1
23
+ $save_every_n_epochs=1
24
+ $mixed_precision="fp16"
25
+ $num_cpu_threads_per_process=6
26
+
27
+ # You should not have to change values past this point
28
+
29
+ $repeats = $image_num * $dataset_repeats
30
+ $mts = [Math]::Ceiling($repeats / $train_batch_size * $epoch)
31
+
32
+ Write-Output "Repeats: $repeats"
33
+ Write-Output "max_train_steps: $mts"
34
+
35
+ cd D:\kohya_ss
36
+ .\venv\Scripts\activate
37
+
38
+ accelerate launch --num_cpu_threads_per_process $num_cpu_threads_per_process train_db_fixed.py `
39
+ --pretrained_model_name_or_path=$pretrained_model_name_or_path `
40
+ --train_data_dir=$data_dir `
41
+ --output_dir=$output_dir `
42
+ --resolution=$resolution `
43
+ --train_batch_size=$train_batch_size `
44
+ --learning_rate=$learning_rate `
45
+ --max_train_steps=$mts `
46
+ --use_8bit_adam `
47
+ --xformers `
48
+ --mixed_precision=$mixed_precision `
49
+ --cache_latents `
50
+ --save_every_n_epochs=$save_every_n_epochs `
51
+ --logging_dir=$logging_dir `
52
+ --save_precision="fp16" `
53
+ --reg_data_dir=$reg_data_dir `
54
+ --lr_scheduler=$lr_scheduler