Fix _ issue

This commit is contained in:
bmaltais 2023-03-23 14:21:02 -04:00
parent 4229d2277a
commit c47cb10384
2 changed files with 16 additions and 3 deletions

View File

@ -192,6 +192,8 @@ This will store your a backup file with your current locally installed pip packa
## Change History
* 2023/03/23 (v21.3.2)
- Fix issue reported: https://github.com/bmaltais/kohya_ss/issues/439
* 2023/03/23 (v21.3.1)
- Merge PR to fix refactor naming issue for basic captions. Thank @zrma
* 2023/03/22 (v21.3.0)

View File

@ -5,6 +5,16 @@ from .common_gui import get_folder_path
import os
def replace_underscore_with_space(folder_path, file_extension):
for file_name in os.listdir(folder_path):
if file_name.endswith(file_extension):
file_path = os.path.join(folder_path, file_name)
with open(file_path, 'r') as file:
file_content = file.read()
new_file_content = file_content.replace('_', ' ')
with open(file_path, 'w') as file:
file.write(new_file_content)
def caption_images(
train_data_dir, caption_extension, batch_size, thresh, replace_underscores
):
@ -26,9 +36,7 @@ def caption_images(
run_cmd = f'accelerate launch "./finetune/tag_images_by_wd14_tagger.py"'
run_cmd += f' --batch_size="{int(batch_size)}"'
run_cmd += f' --thresh="{thresh}"'
run_cmd += f' --replace_underscores' if replace_underscores else ''
if caption_extension != '':
run_cmd += f' --caption_extension="{caption_extension}"'
run_cmd += f' --caption_extension="{caption_extension}"'
run_cmd += f' "{train_data_dir}"'
print(run_cmd)
@ -38,6 +46,9 @@ def caption_images(
os.system(run_cmd)
else:
subprocess.run(run_cmd)
if replace_underscores:
replace_underscore_with_space(train_data_dir, caption_extension)
print('...captioning done')