From 3b4d59877f0f92b0aa7948732740614b85266847 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 5 Feb 2024 13:40:00 -0500 Subject: [PATCH] color grading --- CHANGELOG.md | 6 ++++-- javascript/sdnext.css | 6 ++++-- modules/processing_correction.py | 4 ++-- modules/sd_models.py | 2 +- modules/sd_vae.py | 4 ++-- modules/ui_sections.py | 14 +++++++------- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37845e4ac..b8d2dbaf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - video2video - wuerstchen v3 [pr](https://github.com/huggingface/diffusers/pull/6487) - more pipelines: +- segmoe lora - control api - masking api - preprocess api @@ -37,7 +38,7 @@ Another big release, highlights being: - New models and pipelines: **Segmind SegMoE**, **Mixture Tiling**, **InstaFlow**, **SAG**, **BlipDiffusion** - Massive work integrating latest advances with [OpenVINO](https://github.com/vladmandic/automatic/wiki/OpenVINO), [IPEX](https://github.com/vladmandic/automatic/wiki/Intel-ARC) and [ONNX Olive](https://github.com/vladmandic/automatic/wiki/ONNX-Runtime-&-Olive) -- Full control over brightness, sharpness and color during generate process directly in latent space +- Full control over brightness, sharpness and color shifts and color grading during generate process directly in latent space Plus welcome additions to **UI performance, usability and accessibility** and flexibility of deployment And it also includes fixes for all reported issues so far @@ -48,7 +49,7 @@ As of this release, default backend is set to **diffusers** as its more feature - For more details on all new features see full [CHANGELOG](https://github.com/vladmandic/automatic/blob/master/CHANGELOG.md) - For documentation, see [WIKI](https://github.com/vladmandic/automatic/wiki) -## Update for 2023-02-04 +## Update for 2023-02-05 - **Control**: - add **inpaint** support @@ -253,6 +254,7 @@ As of this release, default backend is set to **diffusers** as its more feature - **correction** - new section in generate, allows for image corrections during generataion directly in latent space - adds *brightness*, *sharpness* and *color* controls, thanks @AI-Casanova + - adds *color grading* controls, thanks @AI-Casanova - replaces old **hdr** section - **IPEX**, thanks @disty0 - see [wiki](https://github.com/vladmandic/automatic/wiki/Intel-ARC) for details diff --git a/javascript/sdnext.css b/javascript/sdnext.css index e4865e03a..b17a0db68 100644 --- a/javascript/sdnext.css +++ b/javascript/sdnext.css @@ -1,5 +1,5 @@ @font-face { font-family: 'NotoSans'; font-display: swap; font-style: normal; font-weight: 100; src: local('NotoSans'), url('notosans-nerdfont-regular.ttf') } -:root { --left-column: 500px; } +:root { --left-column: 550px; } a { font-weight: bold; cursor: pointer; } h2 { margin-top: 1em !important; font-size: var(--text-xxl) !important; } footer { display: none; margin-top: 0 !important;} @@ -9,6 +9,7 @@ tr { border-bottom: none !important; padding: 0.1em 0.5em !important; } textarea { overflow-y: auto !important; } span { font-size: var(--text-md) !important; } button { font-size: var(--text-lg) !important; } +input[type='color'] { width: 64px; height: 32px; } /* gradio elements */ .block .padded:not(.gradio-accordion) { padding: 0 !important; margin-right: 0; min-width: 90px !important; } @@ -50,7 +51,7 @@ button { font-size: var(--text-lg) !important; } .accordion-compact { padding: 8px 0px 4px 0px !important; } .settings-accordion>div { flex-flow: wrap; } .small-accordion .form { min-width: var(--left-column) !important; max-width: max-content; } -.small-accordion .label-wrap .icon { margin-right: 1.6em; margin-left: 0.6em; color: var(--button-primary-border-color); } +.small-accordion .label-wrap .icon { margin-right: 1em; margin-left: 0.3em; color: var(--button-primary-border-color); } .small-accordion .label-wrap { padding: 16px 0px 8px 0px; margin: 0; border-top: 2px solid var(--button-secondary-border-color); } .small-accordion { width: fit-content !important; min-width: fit-content !important; padding-left: 0 !important; } .extension-script { max-width: 48vw; } @@ -111,6 +112,7 @@ div#extras_scale_to_tab div.form{ flex-direction: row; } width: 22em; min-height: 1.3em; font-size: var(--text-xs); transition: opacity 0.2s ease-in; pointer-events: none; opacity: 0; z-index: 999; } .tooltip-show { opacity: 0.9; } .toolbutton-selected { background: var(--background-fill-primary) !important; } +#txt2img_hdr_color_row > div { min-width: unset !important; max-width: unset !important; } /* settings */ #si-sparkline-memo, #si-sparkline-load { background-color: #111; } diff --git a/modules/processing_correction.py b/modules/processing_correction.py index 9593856cc..892c1e8c7 100644 --- a/modules/processing_correction.py +++ b/modules/processing_correction.py @@ -75,9 +75,9 @@ def get_color(colorstr): def color_adjust(tensor, colorstr, ratio): color = get_color(colorstr) + debug(f'HDR tint: str={colorstr} color={color} ratio={ratio}') for i in range(3): - print(color[i]) - tensor[i] = center_tensor(tensor[i], full_shift=1, offset=color[i]*(ratio/3)) + tensor[i] = center_tensor(tensor[i], full_shift=1, offset=color[i]*(ratio/2)) return tensor diff --git a/modules/sd_models.py b/modules/sd_models.py index 5f1b43201..2cf5396cf 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -730,7 +730,7 @@ def move_model(model, device=None): model.to(device) debug_move(f'Model move: to={device} class={model.__class__} function={sys._getframe(1).f_code.co_name}') # pylint: disable=protected-access except Exception as e: - shared.log.error(f'Model move: to={device} {e}') + shared.log.error(f'Model move: to={device} class={model.__class__} {e}') devices.torch_gc() diff --git a/modules/sd_vae.py b/modules/sd_vae.py index 49d244dd4..4cedf0692 100644 --- a/modules/sd_vae.py +++ b/modules/sd_vae.py @@ -241,8 +241,8 @@ def reload_vae_weights(sd_model=None, vae_file=unspecified): return None if shared.backend == shared.Backend.ORIGINAL and (shared.cmd_opts.lowvram or shared.cmd_opts.medvram): lowvram.send_everything_to_cpu() - else: - sd_models.move_model(sd_model, devices.cpu) + # else: + # sd_models.move_model(sd_model, devices.cpu) if shared.backend == shared.Backend.ORIGINAL: sd_hijack.model_hijack.undo_hijack(sd_model) diff --git a/modules/ui_sections.py b/modules/ui_sections.py index 8ae7dca17..c84a4aaad 100644 --- a/modules/ui_sections.py +++ b/modules/ui_sections.py @@ -121,24 +121,24 @@ def create_advanced_inputs(tab): def create_correction_inputs(tab): with gr.Accordion(open=False, label="Corrections", elem_id=f"{tab}_corrections", elem_classes=["small-accordion"], visible=shared.backend == shared.Backend.DIFFUSERS): with gr.Group(visible=shared.backend == shared.Backend.DIFFUSERS): - with gr.Row(): + with gr.Row(elem_id=f"{tab}_hdr_mode_row"): hdr_mode = gr.Dropdown(label="Mode", choices=["Relative values", "Absolute values"], type="index", value="Relative values", elem_id=f"{tab}_hdr_mode", show_label=False) gr.HTML('
') - with gr.Row(): + with gr.Row(elem_id=f"{tab}_correction_row"): hdr_brightness = gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, value=0, label='Brightness', elem_id=f"{tab}_hdr_brightness") hdr_sharpen = gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, value=0, label='Sharpen', elem_id=f"{tab}_hdr_sharpen") hdr_color = gr.Slider(minimum=0.0, maximum=4.0, step=0.1, value=0.0, label='Color', elem_id=f"{tab}_hdr_color") - with gr.Row(): + with gr.Row(elem_id=f"{tab}_hdr_clamp_row"): hdr_clamp = gr.Checkbox(label='HDR clamp', value=False, elem_id=f"{tab}_hdr_clamp") hdr_boundary = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=4.0, label='Range', elem_id=f"{tab}_hdr_boundary") hdr_threshold = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.95, label='Threshold', elem_id=f"{tab}_hdr_threshold") - with gr.Row(): + with gr.Row(elem_id=f"{tab}_hdr_max_row"): hdr_maximize = gr.Checkbox(label='HDR maximize', value=False, elem_id=f"{tab}_hdr_maximize") hdr_max_center = gr.Slider(minimum=0.0, maximum=2.0, step=0.1, value=0.6, label='Center', elem_id=f"{tab}_hdr_max_center") hdr_max_boundry = gr.Slider(minimum=0.5, maximum=2.0, step=0.1, value=1.0, label='Max Range', elem_id=f"{tab}_hdr_max_boundry") - with gr.Row(): - hdr_tint_ratio = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, value=0.0, label='Tint', elem_id=f"{tab}_hdr_tint_ratio") - hdr_color_picker = gr.ColorPicker(label="Color Replace", show_label=False, value=None, elem_id=f"{tab}_hdr_color_picker") + with gr.Row(elem_id=f"{tab}_hdr_color_row"): + hdr_color_picker = gr.ColorPicker(label="Color", show_label=True, container=False, value=None, elem_id=f"{tab}_hdr_color_picker") + hdr_tint_ratio = gr.Slider(label='Tint', minimum=-1.0, maximum=1.0, step=0.05, value=0.0, elem_id=f"{tab}_hdr_tint_ratio") return hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundry, hdr_color_picker, hdr_tint_ratio,