Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
40d1c6e4
Commit
40d1c6e4
authored
Oct 13, 2022
by
Buckzor
Committed by
AUTOMATIC1111
Oct 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Option between stretch and crop for Highres. fix
parent
b2261b53
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
24 deletions
+42
-24
modules/processing.py
modules/processing.py
+22
-12
modules/txt2img.py
modules/txt2img.py
+4
-3
modules/ui.py
modules/ui.py
+16
-9
No files found.
modules/processing.py
View file @
40d1c6e4
...
@@ -506,13 +506,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -506,13 +506,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
firstphase_width_truncated
=
0
firstphase_width_truncated
=
0
firstphase_height_truncated
=
0
firstphase_height_truncated
=
0
def
__init__
(
self
,
enable_hr
=
False
,
scale_latent
=
True
,
denoising_strength
=
0.75
,
first
_pass_width
=
512
,
first_pass_height
=
512
,
**
kwargs
):
def
__init__
(
self
,
enable_hr
=
False
,
scale_latent
=
True
,
denoising_strength
=
0.75
,
first
phase_width
=
512
,
firstphase_height
=
512
,
crop_scale
=
False
,
**
kwargs
):
super
()
.
__init__
(
**
kwargs
)
super
()
.
__init__
(
**
kwargs
)
self
.
enable_hr
=
enable_hr
self
.
enable_hr
=
enable_hr
self
.
scale_latent
=
scale_latent
self
.
scale_latent
=
scale_latent
self
.
denoising_strength
=
denoising_strength
self
.
denoising_strength
=
denoising_strength
self
.
first_pass_width
=
first_pass_width
self
.
firstphase_width
=
firstphase_width
self
.
first_pass_height
=
first_pass_height
self
.
firstphase_height
=
firstphase_height
self
.
crop_scale
=
crop_scale
def
init
(
self
,
all_prompts
,
all_seeds
,
all_subseeds
):
def
init
(
self
,
all_prompts
,
all_seeds
,
all_subseeds
):
if
self
.
enable_hr
:
if
self
.
enable_hr
:
...
@@ -521,14 +522,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -521,14 +522,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
else
:
else
:
state
.
job_count
=
state
.
job_count
*
2
state
.
job_count
=
state
.
job_count
*
2
desired_pixel_count
=
self
.
first_pass_width
*
self
.
first_pass
_height
#desired_pixel_count = self.firstphase_width * self.firstphase
_height
actual_pixel_count
=
self
.
width
*
self
.
height
#
actual_pixel_count = self.width * self.height
scale
=
math
.
sqrt
(
desired_pixel_count
/
actual_pixel_count
)
#
scale = math.sqrt(desired_pixel_count / actual_pixel_count)
self
.
firstphase_width
=
math
.
ceil
(
scale
*
self
.
width
/
64
)
*
64
#
self.firstphase_width = math.ceil(scale * self.width / 64) * 64
self
.
firstphase_height
=
math
.
ceil
(
scale
*
self
.
height
/
64
)
*
64
#
self.firstphase_height = math.ceil(scale * self.height / 64) * 64
self
.
firstphase_width_truncated
=
int
(
scale
*
self
.
width
)
#
self.firstphase_width_truncated = int(scale * self.width)
self
.
firstphase_height_truncated
=
int
(
scale
*
self
.
height
)
#
self.firstphase_height_truncated = int(scale * self.height)
def
sample
(
self
,
conditioning
,
unconditional_conditioning
,
seeds
,
subseeds
,
subseed_strength
):
def
sample
(
self
,
conditioning
,
unconditional_conditioning
,
seeds
,
subseeds
,
subseed_strength
):
self
.
sampler
=
sd_samplers
.
create_sampler_with_index
(
sd_samplers
.
samplers
,
self
.
sampler_index
,
self
.
sd_model
)
self
.
sampler
=
sd_samplers
.
create_sampler_with_index
(
sd_samplers
.
samplers
,
self
.
sampler_index
,
self
.
sd_model
)
...
@@ -541,8 +542,17 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
...
@@ -541,8 +542,17 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
x
=
create_random_tensors
([
opt_C
,
self
.
firstphase_height
//
opt_f
,
self
.
firstphase_width
//
opt_f
],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
self
.
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
x
=
create_random_tensors
([
opt_C
,
self
.
firstphase_height
//
opt_f
,
self
.
firstphase_width
//
opt_f
],
seeds
=
seeds
,
subseeds
=
subseeds
,
subseed_strength
=
self
.
subseed_strength
,
seed_resize_from_h
=
self
.
seed_resize_from_h
,
seed_resize_from_w
=
self
.
seed_resize_from_w
,
p
=
self
)
samples
=
self
.
sampler
.
sample
(
self
,
x
,
conditioning
,
unconditional_conditioning
)
samples
=
self
.
sampler
.
sample
(
self
,
x
,
conditioning
,
unconditional_conditioning
)
truncate_x
=
(
self
.
firstphase_width
-
self
.
firstphase_width_truncated
)
//
opt_f
truncate_x
=
0
truncate_y
=
(
self
.
firstphase_height
-
self
.
firstphase_height_truncated
)
//
opt_f
truncate_y
=
0
if
self
.
crop_scale
:
if
self
.
width
/
self
.
firstphase_width
>
self
.
height
/
self
.
firstphase_height
:
#Crop to landscape
truncate_y
=
(
self
.
width
-
self
.
firstphase_width
)
//
2
//
opt_f
elif
self
.
width
/
self
.
firstphase_width
<
self
.
height
/
self
.
firstphase_height
:
#Crop to portrait
truncate_x
=
(
self
.
height
-
self
.
firstphase_height
)
//
2
//
opt_f
samples
=
samples
[:,
:,
truncate_y
//
2
:
samples
.
shape
[
2
]
-
truncate_y
//
2
,
truncate_x
//
2
:
samples
.
shape
[
3
]
-
truncate_x
//
2
]
samples
=
samples
[:,
:,
truncate_y
//
2
:
samples
.
shape
[
2
]
-
truncate_y
//
2
,
truncate_x
//
2
:
samples
.
shape
[
3
]
-
truncate_x
//
2
]
...
...
modules/txt2img.py
View file @
40d1c6e4
...
@@ -6,7 +6,7 @@ import modules.processing as processing
...
@@ -6,7 +6,7 @@ import modules.processing as processing
from
modules.ui
import
plaintext_to_html
from
modules.ui
import
plaintext_to_html
def
txt2img
(
prompt
:
str
,
negative_prompt
:
str
,
prompt_style
:
str
,
prompt_style2
:
str
,
steps
:
int
,
sampler_index
:
int
,
restore_faces
:
bool
,
tiling
:
bool
,
n_iter
:
int
,
batch_size
:
int
,
cfg_scale
:
float
,
seed
:
int
,
subseed
:
int
,
subseed_strength
:
float
,
seed_resize_from_h
:
int
,
seed_resize_from_w
:
int
,
seed_enable_extras
:
bool
,
height
:
int
,
width
:
int
,
enable_hr
:
bool
,
scale_latent
:
bool
,
denoising_strength
:
float
,
first
_pass_width
:
int
,
first_pass_height
:
int
,
*
args
):
def
txt2img
(
prompt
:
str
,
negative_prompt
:
str
,
prompt_style
:
str
,
prompt_style2
:
str
,
steps
:
int
,
sampler_index
:
int
,
restore_faces
:
bool
,
tiling
:
bool
,
n_iter
:
int
,
batch_size
:
int
,
cfg_scale
:
float
,
seed
:
int
,
subseed
:
int
,
subseed_strength
:
float
,
seed_resize_from_h
:
int
,
seed_resize_from_w
:
int
,
seed_enable_extras
:
bool
,
height
:
int
,
width
:
int
,
enable_hr
:
bool
,
scale_latent
:
bool
,
denoising_strength
:
float
,
first
phase_width
:
int
,
firstphase_height
:
int
,
crop_scale
:
bool
,
*
args
):
p
=
StableDiffusionProcessingTxt2Img
(
p
=
StableDiffusionProcessingTxt2Img
(
sd_model
=
shared
.
sd_model
,
sd_model
=
shared
.
sd_model
,
outpath_samples
=
opts
.
outdir_samples
or
opts
.
outdir_txt2img_samples
,
outpath_samples
=
opts
.
outdir_samples
or
opts
.
outdir_txt2img_samples
,
...
@@ -32,8 +32,9 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2:
...
@@ -32,8 +32,9 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2:
enable_hr
=
enable_hr
,
enable_hr
=
enable_hr
,
scale_latent
=
scale_latent
if
enable_hr
else
None
,
scale_latent
=
scale_latent
if
enable_hr
else
None
,
denoising_strength
=
denoising_strength
if
enable_hr
else
None
,
denoising_strength
=
denoising_strength
if
enable_hr
else
None
,
first_pass_width
=
first_pass_width
if
enable_hr
else
None
,
firstphase_width
=
firstphase_width
if
enable_hr
else
None
,
first_pass_height
=
first_pass_height
if
enable_hr
else
None
,
firstphase_height
=
firstphase_height
if
enable_hr
else
None
,
crop_scale
=
crop_scale
if
enable_hr
else
None
,
)
)
...
...
modules/ui.py
View file @
40d1c6e4
...
@@ -540,12 +540,18 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -540,12 +540,18 @@ def create_ui(wrap_gradio_gpu_call):
enable_hr
=
gr
.
Checkbox
(
label
=
'Highres. fix'
,
value
=
False
)
enable_hr
=
gr
.
Checkbox
(
label
=
'Highres. fix'
,
value
=
False
)
with
gr
.
Row
(
visible
=
False
)
as
hr_options
:
with
gr
.
Row
(
visible
=
False
)
as
hr_options
:
first_pass_width
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
1024
,
step
=
64
,
label
=
"First pass width"
,
value
=
512
)
with
gr
.
Column
(
scale
=
1.0
):
first_pass_height
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
1024
,
step
=
64
,
label
=
"First pass height"
,
value
=
512
)
firstphase_width
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
1024
,
step
=
64
,
label
=
"First pass width"
,
value
=
512
)
firstphase_height
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
1024
,
step
=
64
,
label
=
"First pass height"
,
value
=
512
)
with
gr
.
Column
(
scale
=
1.0
):
with
gr
.
Row
():
crop_scale
=
gr
.
Checkbox
(
label
=
'Crop when scaling'
,
value
=
False
)
scale_latent
=
gr
.
Checkbox
(
label
=
'Scale latent'
,
value
=
False
)
scale_latent
=
gr
.
Checkbox
(
label
=
'Scale latent'
,
value
=
False
)
with
gr
.
Row
():
denoising_strength
=
gr
.
Slider
(
minimum
=
0.0
,
maximum
=
1.0
,
step
=
0.01
,
label
=
'Denoising strength'
,
value
=
0.7
)
denoising_strength
=
gr
.
Slider
(
minimum
=
0.0
,
maximum
=
1.0
,
step
=
0.01
,
label
=
'Denoising strength'
,
value
=
0.7
)
with
gr
.
Row
():
with
gr
.
Row
(
equal_height
=
True
):
batch_count
=
gr
.
Slider
(
minimum
=
1
,
step
=
1
,
label
=
'Batch count'
,
value
=
1
)
batch_count
=
gr
.
Slider
(
minimum
=
1
,
step
=
1
,
label
=
'Batch count'
,
value
=
1
)
batch_size
=
gr
.
Slider
(
minimum
=
1
,
maximum
=
8
,
step
=
1
,
label
=
'Batch size'
,
value
=
1
)
batch_size
=
gr
.
Slider
(
minimum
=
1
,
maximum
=
8
,
step
=
1
,
label
=
'Batch size'
,
value
=
1
)
...
@@ -606,8 +612,9 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -606,8 +612,9 @@ def create_ui(wrap_gradio_gpu_call):
enable_hr
,
enable_hr
,
scale_latent
,
scale_latent
,
denoising_strength
,
denoising_strength
,
first_pass_width
,
firstphase_width
,
first_pass_height
,
firstphase_height
,
crop_scale
,
]
+
custom_inputs
,
]
+
custom_inputs
,
outputs
=
[
outputs
=
[
txt2img_gallery
,
txt2img_gallery
,
...
@@ -672,8 +679,8 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -672,8 +679,8 @@ def create_ui(wrap_gradio_gpu_call):
(
denoising_strength
,
"Denoising strength"
),
(
denoising_strength
,
"Denoising strength"
),
(
enable_hr
,
lambda
d
:
"Denoising strength"
in
d
),
(
enable_hr
,
lambda
d
:
"Denoising strength"
in
d
),
(
hr_options
,
lambda
d
:
gr
.
Row
.
update
(
visible
=
"Denoising strength"
in
d
)),
(
hr_options
,
lambda
d
:
gr
.
Row
.
update
(
visible
=
"Denoising strength"
in
d
)),
(
first
_pass
_width
,
"First pass width"
),
(
first
phase
_width
,
"First pass width"
),
(
first
_pass
_height
,
"First pass height"
),
(
first
phase
_height
,
"First pass height"
),
]
]
modules
.
generation_parameters_copypaste
.
connect_paste
(
paste
,
txt2img_paste_fields
,
txt2img_prompt
)
modules
.
generation_parameters_copypaste
.
connect_paste
(
paste
,
txt2img_paste_fields
,
txt2img_prompt
)
token_button
.
click
(
fn
=
update_token_counter
,
inputs
=
[
txt2img_prompt
,
steps
],
outputs
=
[
token_counter
])
token_button
.
click
(
fn
=
update_token_counter
,
inputs
=
[
txt2img_prompt
,
steps
],
outputs
=
[
token_counter
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment