Skip to content

Commit

Permalink
Merge pull request kohya-ss#300 from bmaltais/dev
Browse files Browse the repository at this point in the history
v21.1.3
  • Loading branch information
bmaltais authored Mar 4, 2023
2 parents a1551fc + 3f45448 commit d1b8af9
Show file tree
Hide file tree
Showing 21 changed files with 266 additions and 74 deletions.
12 changes: 12 additions & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ PowerShellを使う場合、venvを使えるようにするためには以下の
- 「Set-ExecutionPolicy Unrestricted」と入力し、Yと答えます。
- 管理者のPowerShellを閉じます。

## Ubuntu環境でのインストール

```
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
bash ubuntu_setup.sh
```

をコマンドプロンプトで実行し、tkをインストールし、accelerateの質問をWindowsと同じように答えます。

`./gui.sh`でGUIを実行します。

## Windows環境でのインストール

以下の例ではPyTorchは1.12.1/CUDA 11.6版をインストールします。CUDA 11.3版やPyTorch 1.13を使う場合は適宜書き換えください。
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ If you run on Linux and would like to use the GUI, there is now a port of it as

## Installation

### Ubuntu
In the terminal, run

```
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss
bash ubuntu_setup.sh
```

then configure accelerate with the same answers as in the Windows instructions when prompted.

### Windows

Give unrestricted script access to powershell so venv can work:

- Run PowerShell as an administrator
Expand Down Expand Up @@ -163,6 +176,9 @@ This will store your a backup file with your current locally installed pip packa

## Change History

* 2023/03/04 (v21.1.3):
- Fix progress bar being displayed when not required.
- Add support for linux, thank you @devNegative-asm
* 2023/03/03 (v21.1.2):
- Fix issue https://github.com/bmaltais/kohya_ss/issues/277
- Fix issue https://github.com/bmaltais/kohya_ss/issues/278 introduce by LoCon project switching to pip module. Make sure to run upgrade.ps1 to install the latest pip requirements for LoCon support.
Expand Down
30 changes: 23 additions & 7 deletions dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
gradio_config,
gradio_source_model,
set_legacy_8bitadam,
my_data,
update_my_data,
)
from library.tensorboard_gui import (
gradio_tensorboard,
Expand Down Expand Up @@ -214,7 +214,7 @@ def open_configuration(
my_data = json.load(f)
print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data)
my_data = update_my_data(my_data)
else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data = {}
Expand Down Expand Up @@ -456,7 +456,7 @@ def train_model(

print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')
Expand Down Expand Up @@ -500,7 +500,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small'
)
train_data_dir_input_folder.click(
get_folder_path, outputs=train_data_dir
get_folder_path,
outputs=train_data_dir,
show_progress=False,
)
reg_data_dir = gr.Textbox(
label='Regularisation folder',
Expand All @@ -510,7 +512,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small'
)
reg_data_dir_input_folder.click(
get_folder_path, outputs=reg_data_dir
get_folder_path,
outputs=reg_data_dir,
show_progress=False,
)
with gr.Row():
output_dir = gr.Textbox(
Expand All @@ -529,7 +533,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small'
)
logging_dir_input_folder.click(
get_folder_path, outputs=logging_dir
get_folder_path,
outputs=logging_dir,
show_progress=False,
)
with gr.Row():
output_name = gr.Textbox(
Expand Down Expand Up @@ -610,7 +616,11 @@ def dreambooth_tab(
placeholder='(Optiona) path to checkpoint of vae to replace for training',
)
vae_button = gr.Button('📂', elem_id='open_folder_small')
vae_button.click(get_any_file_path, outputs=vae)
vae_button.click(
get_any_file_path,
outputs=vae,
show_progress=False,
)
(
use_8bit_adam,
xformers,
Expand Down Expand Up @@ -664,10 +674,12 @@ def dreambooth_tab(
button_start_tensorboard.click(
start_tensorboard,
inputs=logging_dir,
show_progress=False,
)

button_stop_tensorboard.click(
stop_tensorboard,
show_progress=False,
)

settings_list = [
Expand Down Expand Up @@ -730,23 +742,27 @@ def dreambooth_tab(
open_configuration,
inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list,
show_progress=False,
)

button_save_config.click(
save_configuration,
inputs=[dummy_db_false, config_file_name] + settings_list,
outputs=[config_file_name],
show_progress=False,
)

button_save_as_config.click(
save_configuration,
inputs=[dummy_db_true, config_file_name] + settings_list,
outputs=[config_file_name],
show_progress=False,
)

button_run.click(
train_model,
inputs=settings_list,
show_progress=False,
)

return (
Expand Down
44 changes: 29 additions & 15 deletions finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
color_aug_changed,
run_cmd_training,
set_legacy_8bitadam,
my_data,
update_my_data,
)
from library.tensorboard_gui import (
gradio_tensorboard,
Expand All @@ -33,6 +33,8 @@
save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄

PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'


def save_configuration(
save_as,
Expand Down Expand Up @@ -216,7 +218,7 @@ def open_config_file(
my_data_db = json.load(f)
print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data)
my_data = update_my_data(my_data)
else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data_db = {}
Expand Down Expand Up @@ -295,9 +297,7 @@ def train_model(
if not os.path.exists(train_dir):
os.mkdir(train_dir)

run_cmd = (
f'./venv/Scripts/python.exe finetune/merge_captions_to_metadata.py'
)
run_cmd = f'{PYTHON} finetune/merge_captions_to_metadata.py'
if caption_extension == '':
run_cmd += f' --caption_extension=".caption"'
else:
Expand All @@ -310,13 +310,11 @@ def train_model(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

# create images buckets
if generate_image_buckets:
run_cmd = (
f'./venv/Scripts/python.exe finetune/prepare_buckets_latents.py'
)
run_cmd = f'{PYTHON} finetune/prepare_buckets_latents.py'
run_cmd += f' "{image_folder}"'
run_cmd += f' "{train_dir}/{caption_metadata_filename}"'
run_cmd += f' "{train_dir}/{latent_metadata_filename}"'
Expand All @@ -334,7 +332,7 @@ def train_model(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

image_num = len(
[
Expand Down Expand Up @@ -444,7 +442,7 @@ def train_model(

print(run_cmd)
# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

# check if output_dir/last is a folder... therefore it is a diffuser model
last_dir = pathlib.Path(f'{output_dir}/{output_name}')
Expand Down Expand Up @@ -490,7 +488,11 @@ def finetune_tab():
train_dir_folder = gr.Button(
folder_symbol, elem_id='open_folder_small'
)
train_dir_folder.click(get_folder_path, outputs=train_dir)
train_dir_folder.click(
get_folder_path,
outputs=train_dir,
show_progress=False,
)

image_folder = gr.Textbox(
label='Training Image folder',
Expand All @@ -500,7 +502,9 @@ def finetune_tab():
folder_symbol, elem_id='open_folder_small'
)
image_folder_input_folder.click(
get_folder_path, outputs=image_folder
get_folder_path,
outputs=image_folder,
show_progress=False,
)
with gr.Row():
output_dir = gr.Textbox(
Expand All @@ -510,7 +514,11 @@ def finetune_tab():
output_dir_input_folder = gr.Button(
folder_symbol, elem_id='open_folder_small'
)
output_dir_input_folder.click(get_folder_path, outputs=output_dir)
output_dir_input_folder.click(
get_folder_path,
outputs=output_dir,
show_progress=False,
)

logging_dir = gr.Textbox(
label='Logging folder',
Expand All @@ -520,7 +528,9 @@ def finetune_tab():
folder_symbol, elem_id='open_folder_small'
)
logging_dir_input_folder.click(
get_folder_path, outputs=logging_dir
get_folder_path,
outputs=logging_dir,
show_progress=False,
)
with gr.Row():
output_name = gr.Textbox(
Expand Down Expand Up @@ -654,6 +664,7 @@ def finetune_tab():

button_stop_tensorboard.click(
stop_tensorboard,
show_progress=False,
)

settings_list = [
Expand Down Expand Up @@ -724,18 +735,21 @@ def finetune_tab():
open_config_file,
inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list,
show_progress=False,
)

button_save_config.click(
save_configuration,
inputs=[dummy_ft_false, config_file_name] + settings_list,
outputs=[config_file_name],
show_progress=False,
)

button_save_as_config.click(
save_configuration,
inputs=[dummy_ft_true, config_file_name] + settings_list,
outputs=[config_file_name],
show_progress=False,
)


Expand Down
3 changes: 3 additions & 0 deletions gui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source venv/bin/activate
python kohya_gui.py
8 changes: 6 additions & 2 deletions library/basic_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from easygui import msgbox
import subprocess
from .common_gui import get_folder_path, add_pre_postfix, find_replace
import os


def caption_images(
Expand Down Expand Up @@ -38,7 +39,7 @@ def caption_images(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

if overwrite_input:
if not prefix == '' or not postfix == '':
Expand Down Expand Up @@ -85,7 +86,9 @@ def gradio_basic_caption_gui_tab():
'📂', elem_id='open_folder_small'
)
button_images_dir_input.click(
get_folder_path, outputs=images_dir_input
get_folder_path,
outputs=images_dir_input,
show_progress=False,
)
caption_file_ext = gr.Textbox(
label='Caption file extension',
Expand Down Expand Up @@ -139,4 +142,5 @@ def gradio_basic_caption_gui_tab():
find,
replace,
],
show_progress=False,
)
11 changes: 8 additions & 3 deletions library/blip_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
from .common_gui import get_folder_path, add_pre_postfix

PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'


def caption_images(
train_data_dir,
Expand Down Expand Up @@ -32,7 +34,7 @@ def caption_images(
return

print(f'Captioning files in {train_data_dir}...')
run_cmd = f'.\\venv\\Scripts\\python.exe "finetune/make_captions.py"'
run_cmd = f'{PYTHON} "finetune/make_captions.py"'
run_cmd += f' --batch_size="{int(batch_size)}"'
run_cmd += f' --num_beams="{int(num_beams)}"'
run_cmd += f' --top_p="{top_p}"'
Expand All @@ -48,7 +50,7 @@ def caption_images(
print(run_cmd)

# Run the command
subprocess.run(run_cmd)
os.system(run_cmd)

# Add prefix and postfix
add_pre_postfix(
Expand Down Expand Up @@ -81,7 +83,9 @@ def gradio_blip_caption_gui_tab():
'📂', elem_id='open_folder_small'
)
button_train_data_dir_input.click(
get_folder_path, outputs=train_data_dir
get_folder_path,
outputs=train_data_dir,
show_progress=False,
)
with gr.Row():
caption_file_ext = gr.Textbox(
Expand Down Expand Up @@ -138,4 +142,5 @@ def gradio_blip_caption_gui_tab():
prefix,
postfix,
],
show_progress=False,
)
Loading

0 comments on commit d1b8af9

Please sign in to comment.