d8ahazard / sd_dreambooth_extension

Other
1.86k stars 283 forks source link

Text file [filewords] recognition #411

Closed wktra closed 1 year ago

wktra commented 1 year ago

I would like for Dreambooth to properly recognize an accompanying text file with descriptions.

As of right now, I have files that look like this:

pic01.png pic01.txt pic02.png pic02.txt pic03.png pic03.txt

And within each file, exists this type of description: 1girl, bare shoulders, barefoot, breasts, cleavage, cleavage cutout, clothing cutout, demon girl, demon horns, demon tail, demon wings, eyebrows visible through hair, full body, heart cutout, horns, pointy ears, looking at viewer, medium breasts, navel, navel cutout, pink eyes, pink hair, short hair, simple background, solo, standing, stirrup legwear, tail, toeless legwear, toenails, toes, white background, wings, back double bun

When choosing filewords as my instance prompt, DB throws up this error in Windows:

File "Q:\AI\Super_SD_2.0\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2317, in save
    fp = builtins.open(filename, "w+b")
OSError: [Errno 22] Invalid argument: 'Q:\\AI\\Super_SD_2.0\\stable-diffusion-webui\\models\\dreambooth\\testmodel\\samples\\testmodelxyz 1girl bangs blunt bangs blush breasts cleavage cleavage cutout clothing cutout demon girl demon horns demon tail demon wings eyebrows visible through hair full body heart cutout horns looking at viewer medium breasts nail polish navel open mouth pink eyes pink hair pink nails pointy ears simple background solo stirrup legwear tail toeless legwear toenail polish toenails toes twintails wings double hair bun500-0.png'
[*] Weights saved at Q:\AI\Super_SD_2.0\stable-diffusion-webui\models\dreambooth\testmodel

I'm not an intelligent enough gal to assume that it's an issue, so I'm going to assume that it's just a feature that's not implemented. The best I can guess is that DB thinks everything is a captioned filename.

rabidcopy commented 1 year ago

Looks like a path length issue. Could try https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/. Although I could have sworn this repo trimmed preview sample filenames so this wouldn't occur.. In my experience it has always cut off the filename well before then, much less the full instance prompt. But I'm on Linux so..

wktra commented 1 year ago

Looks like a path length issue. Could try https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/. Although I could have sworn this repo trimmed preview sample filenames so this wouldn't occur.. In my experience it has always cut off the filename well before then, much less the full instance prompt. But I'm on Linux so..

@rabidcopy Full instance prompt? The full instance prompt is in a text file with a one word filename.

You mean the path is too long because of all the directories?

Jonseed commented 1 year ago

I'm getting the same error, and I think it has to do with the filename length. It needs to be truncated.

wktra commented 1 year ago

@Jonseed

It's a bug. The webui is mangling and adding some unnecessary code when we fill out the path to the dataset.

Here's how to bypass the bug:

Set the webui to use a concept file. Specifically "concepts_list.json"

Mine looks like this:

[
    {
        "max_steps": -1,
        "instance_data_dir": "Q:\\AI\\trainings\\catgirl99\\processed",
        "class_data_dir": "Q:\\AI\\regularization\\waifugirls",
        "file_prompt_contents": "Instance + Class + Description",
        "instance_prompt": "[filewords]",
        "class_prompt": "girl",
        "save_sample_prompt": "catgirl99",
        "instance_token": "catgirl99",
        "class_token": "girl",
        "num_class_images": 400,
        "class_negative_prompt": "",
        "class_guidance_scale": 7.5,
        "class_infer_steps": 40,
        "save_sample_negative_prompt": "",
        "n_save_sample": 1,
        "sample_seed": -1,
        "save_guidance_scale": 7.5,
        "save_infer_steps": 40
    }
]

Here's what my "catgirl99_01.txt" looks like:

catgirl99 girl, bare shoulders, barefoot, breasts, cleavage, cleavage cutout, clothing cutout,cat girl, cat ears, cat tail, eyebrows visible through hair, full body, looking at viewer, medium breasts, navel,

Fill out the instance prompt and class token as you've been doing. Point the webui to the path to the json concept list file.

That worked for me.

d8ahazard commented 1 year ago

Try with the newest version, I just pushed a bunch of changes that will probably break things in new and exciting places.

wktra commented 1 year ago

sigh. I'll pass...

ItsOkayItsOfficial commented 1 year ago

Yeah this is still an issue on the newest release but unfortunately the workaround @wktra proposed for some reason makes the sample prompt either an empty string or your garbled instance token.

The config.json below returns the following error:

Exception with the stupid image again: [Errno 22] Invalid argument: 'C:\\Users\\ItsOkayItsOfficial\\Desktop\\Code\\stable-diffusion-webui\\models\\dreambooth\\agdb1\\samples\\agdb-1 woman with curly hair is holding a cell phone up to her ear and looking at the camera with a serious look on her face blurry blurry_background blurry_foreground closed_mouth depth_of_field greyscale lips looking_at_viewer monochrome motion_blur photo_medium photorealistic realistic solo4579-0.png' Traceback (most recent call last): File "C:\Users\ItsOkayItsOfficial\Desktop\Code\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 885, in save_weights s_image.save( File "C:\Users\ItsOkayItsOfficial\Desktop\Code\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2317, in save fp = builtins.open(filename, "w+b") OSError: [Errno 22] Invalid argument: 'C:\\Users\\ItsOkayItsOfficial\\Desktop\\Code\\stable-diffusion-webui\\models\\dreambooth\\agdb1\\samples\\agdb-1 woman with curly hair is holding a cell phone up to her ear and looking at the camera with a serious look on her face blurry blurry_background blurry_foreground closed_mouth depth_of_field greyscale lips looking_at_viewer monochrome motion_blur photo_medium photorealistic realistic solo4579-0.png'

    "max_steps": -1,
    "instance_data_dir": "G:\\Stable Diffusion\\ag\\training",
    "class_data_dir": "G:\\Stable Diffusion\\ag\\classifications",
    "file_prompt_contents": "Class Token + Description",
    "instance_prompt": "[filewords]",
    "class_prompt": "[filewords]",
    "save_sample_prompt": "[filewords]",
    "save_sample_template": "",
    "instance_token": "agdb-1",
    "class_token": "woman",
    "num_class_images": 320,
    "class_negative_prompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
    "class_guidance_scale": 10,
    "class_infer_steps": 100,
    "save_sample_negative_prompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
    "n_save_sample": 1,
    "sample_seed": -1,
    "save_guidance_scale": 10,
    "save_infer_steps": 50

The config.json below throws no error but the sample image generated (agdb-14529-0.png) is of a potted plant.

    "max_steps": -1,
    "instance_data_dir": "G:\\Stable Diffusion\\ag\\training",
    "class_data_dir": "G:\\Stable Diffusion\\ag\\classifications",
    "file_prompt_contents": "Class Token + Description",
    "instance_prompt": "[filewords]",
    "class_prompt": "[filewords]",
    "save_sample_prompt": "agdb-1",
    "save_sample_template": "",
    "instance_token": "agdb-1",
    "class_token": "woman",
    "num_class_images": 320,
    "class_negative_prompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
    "class_guidance_scale": 10,
    "class_infer_steps": 100,
    "save_sample_negative_prompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
    "n_save_sample": 1,
    "sample_seed": -1,
    "save_guidance_scale": 10,
    "save_infer_steps": 50
wktra commented 1 year ago

@ItsOkayItsOfficial

The only way that I've ever gotten a save sample prompt to give me anything even remotely accurate is to fill it with very specific descriptions of the character I'm trying to create.

Despite the bad sample preview image, How does the model actually perform when you use prompts to generate your character?

ItsOkayItsOfficial commented 1 year ago

@ItsOkayItsOfficial

The only way that I've ever gotten a save sample prompt to give me anything even remotely accurate is to fill it with very specific descriptions of the character I'm trying to create.

Despite the bad sample preview image, How does the model actually perform when you use prompts to generate your character?

Really? The samples that don't crash my training session have always been pretty solid for me. What do your [filewords] look like?

Below is an example [filewords] prompt: a woman with a black shirt and a black top is taking a selfie in a mirror in a bathroom 1girl asian closed_mouth freckles lips looking_at_viewer mole mole_on_breast mole_on_thigh mole_under_eye realistic short_hair solo

Based on my config that will construct a prompt that outputs by step 1500 a pretty fit sample image : agdb-1 a woman with a black shirt and a black top is taking a selfie in a mirror in a bathroom 1girl asian closed_mouth freckles lips looking_at_viewer mole mole_on_breast mole_on_thigh mole_under_eye realistic short_hair solo

d8ahazard commented 1 year ago

Sure looks like the issue is the filename is too long. Use the "Save class captions to TXT" box in the UI. Adding that option and not making it default was a mistake, which I will be remedying as soon as I push the next big update...by removing the checkbox and defaulting back to saving to txt.

On Fri, Dec 9, 2022 at 3:34 PM wktra @.***> wrote:

@ItsOkayItsOfficial https://github.com/ItsOkayItsOfficial

The only way that I've ever gotten a save sample prompt to give me anything even remotely accurate is to fill it with very specific descriptions of the character I'm trying to create.

Despite the bad sample preview image, How does the model actually perform when you use prompts to generate your character?

— Reply to this email directly, view it on GitHub https://github.com/d8ahazard/sd_dreambooth_extension/issues/411#issuecomment-1344803887, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMO4NF7MYIWH4BXUT5QQ4TWMOQXVANCNFSM6AAAAAASTGSYYY . You are receiving this because you commented.Message ID: @.***>

ItsOkayItsOfficial commented 1 year ago

I agree, and it appears like it might be one of the library modules that's not handling it well, not your code.

Sure looks like the issue is the filename is too long. Use the "Save class captions to TXT" box in the UI. Adding that option and not making it default was a mistake, which I will be remedying as soon as I push the next big update...by removing the checkbox and defaulting back to saving to txt. On Fri, Dec 9, 2022 at 3:34 PM wktra @.> wrote: @ItsOkayItsOfficial https://github.com/ItsOkayItsOfficial The only way that I've ever gotten a save sample prompt to give me anything even remotely accurate is to fill it with very specific descriptions of the character I'm trying to create. Despite the bad sample preview image, How does the model actually perform when you use prompts to generate your character? — Reply to this email directly, view it on GitHub <#411 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMO4NF7MYIWH4BXUT5QQ4TWMOQXVANCNFSM6AAAAAASTGSYYY . You are receiving this because you commented.Message ID: @.>

wktra commented 1 year ago

Okay, so can you please clear something up for me? @ItsOkayItsOfficial

Is this an example of one of your training images filename:

C:\Users\ItsOkayItsOfficial\Desktop\Code\stable-diffusion-webui\models\dreambooth\agdb1\samples\agdb-1 woman with curly hair is holding a cell phone up to her ear and looking at the camera with a serious look on her face blurry blurry_background blurry_foreground closed_mouth depth_of_field greyscale lips looking_at_viewer monochrome motion_blur photo_medium photorealistic realistic solo4579-0.png'

Because if that's true, then @d8ahazard is correct. That filename is WAY TOO LONG.

ItsOkayItsOfficial commented 1 year ago

Of course it is; default path limitation on Windows is 260 characters. But I have no control over that as getting it to save sample images leaves you with the option to use the [filewords] prompt or a limited manually defined prompt.

The issue is that it's not truncating the [filewords] prompt when saving images with the pompt as the file name. Ideally it would just save the image as {token}{class}{checkpoint}.png and have the full prompt as a tEXt chunk in the PNG itself.

Okay, so can you please clear something up for me? @ItsOkayItsOfficial

Is this an example of one of your training images filename:

C:\Users\ItsOkayItsOfficial\Desktop\Code\stable-diffusion-webui\models\dreambooth\agdb1\samples**agdb-1 woman with curly hair is holding a cell phone up to her ear and looking at the camera with a serious look on her face blurry blurry_background blurry_foreground closed_mouth depth_of_field greyscale lips looking_at_viewer monochrome motion_blur photo_medium photorealistic realistic solo4579-0.png'**

Because if that's true, then @d8ahazard is correct. That filename is WAY TOO LONG.

wktra commented 1 year ago

@ItsOkayItsOfficial

I think I get it. it was frustrating earlier because the advice I kept getting everywhere was "shorten your damn filenames!"

and I was like "Excuse me, but my training filenames are named image01.png, image02.png, etc etc. Are you asking me to shorten the captions in image01.txt, image02.txt, image03.txt???"

As if it were my files that were the problem and not what DB was doing with them.

d8ahazard commented 1 year ago

This is now resolved.