stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: Add "Restore faces" as option to the X/Y/Z plot

Open detkov opened this issue 1 year ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

I looked through all the issues and discussion with the search prompt "restore faces" and "plot" and have not found nothing related, so seems like this is a new idea. Correct me if I'm wrong.

The idea is simple: I want to have an ability to compare the generation results without and with "Restore faces" option turned on. Moreover, I would like it to be like in the "Samplers" option, having an options to choose: what face restorers to use (GFPGAN, CodeFormer, etc.). Also, if using the last idea, we have to be able to define model's params, like in CodeFormer.

TLDR: add axis for "Restore faces".

Proposed workflow

  1. Go to "txt2img"
  2. Press "Script" > "X/Y/Z plot"
  3. Press on "X type" (or "Y type" or "Z type")
  4. Choose "Restore faces" from all the available options
  5. Press on the book pic next to "X values"
  6. After that, the possible options will be displayed in "X values", say: GFPGAN, CodeFormer=0.5
  7. Edit the "X values" field as you like (you may change the CodeFormer=0.5 to CodeFormer=0.85 or any other float 0 < x < 1)
  8. Press "Generate"

Additional information

No response

detkov avatar Mar 08 '23 09:03 detkov

edit: okay I opened my first PR here: https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/8435

until then you patch the code manually:

add this to scripts/xyz_grid.py:

first add the option to axis_options:

AxisOption("Face restore", str, apply_face_restore, format_value=format_value),

then add apply_face_restore:

def apply_face_restore(p, opt, x):
    opt = opt.lower()
    if opt == 'codeformer':
        is_active = True
        p.face_restoration_model = 'CodeFormer'
    elif opt == 'gfpgan':
        is_active = True
        p.face_restoration_model = 'GFPGAN'
    else:
        is_active = opt in ('true', 'yes', 'y', '1')

    p.restore_faces = is_active

here I rendered something with low sampling steps intentionally: image

notice the options are either: one of yes, y, true, 1 to use the model specified in settings or specifically either codeformer or gfpgan anything else is interpreted as false.

hananbeer avatar Mar 09 '23 02:03 hananbeer