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
f1ff932c
Commit
f1ff932c
authored
Dec 08, 2023
by
CodeHatchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formatted soft_inpainting.
parent
b2414476
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
scripts/soft_inpainting.py
scripts/soft_inpainting.py
+16
-10
No files found.
scripts/soft_inpainting.py
View file @
f1ff932c
...
...
@@ -122,7 +122,7 @@ def get_modified_nmask(settings, nmask, sigma):
def
apply_adaptive_masks
(
settings
:
SoftInpaintingSettings
,
settings
:
SoftInpaintingSettings
,
nmask
,
latent_orig
,
latent_processed
,
...
...
@@ -137,10 +137,10 @@ def apply_adaptive_masks(
# TODO: Bias the blending according to the latent mask, add adjustable parameter for bias control.
latent_mask
=
nmask
[
0
]
.
float
()
# convert the original mask into a form we use to scale distances for thresholding
mask_scalar
=
1
-
(
torch
.
clamp
(
latent_mask
,
min
=
0
,
max
=
1
)
**
(
settings
.
mask_blend_scale
/
2
))
mask_scalar
=
(
0.5
*
(
1
-
settings
.
composite_mask_influence
)
mask_scalar
=
1
-
(
torch
.
clamp
(
latent_mask
,
min
=
0
,
max
=
1
)
**
(
settings
.
mask_blend_scale
/
2
))
mask_scalar
=
(
0.5
*
(
1
-
settings
.
composite_mask_influence
)
+
mask_scalar
*
settings
.
composite_mask_influence
)
mask_scalar
=
mask_scalar
/
(
1.00001
-
mask_scalar
)
mask_scalar
=
mask_scalar
/
(
1.00001
-
mask_scalar
)
mask_scalar
=
mask_scalar
.
cpu
()
.
numpy
()
latent_distance
=
torch
.
norm
(
latent_processed
-
latent_orig
,
p
=
2
,
dim
=
1
)
...
...
@@ -276,6 +276,7 @@ def weighted_histogram_filter(img, kernel, kernel_center, percentile_min=0.0, pe
An element of the histogram, its weight
and bounds.
"""
def
__init__
(
self
,
value
,
weight
):
self
.
value
:
float
=
value
self
.
weight
:
float
=
weight
...
...
@@ -355,6 +356,7 @@ def weighted_histogram_filter(img, kernel, kernel_center, percentile_min=0.0, pe
return
img_out
def
smoothstep
(
x
):
"""
The smoothstep function, input should be clamped to 0-1 range.
...
...
@@ -362,6 +364,7 @@ def smoothstep(x):
"""
return
x
*
x
*
(
3
-
2
*
x
)
def
smootherstep
(
x
):
"""
The smootherstep function, input should be clamped to 0-1 range.
...
...
@@ -385,6 +388,7 @@ def get_gaussian_kernel(stddev_radius=1.0, max_radius=2):
Returns:
(nparray, nparray): A kernel array (shape: (N, N)), its center coordinate (shape: (2))
"""
# Evaluates a 0-1 normalized gaussian function for a given square distance from the mean.
def
gaussian
(
sqr_mag
):
return
math
.
exp
(
-
sqr_mag
/
(
stddev_radius
*
stddev_radius
))
...
...
@@ -656,7 +660,8 @@ class Script(scripts.Script):
# p.extra_generation_params["Mask rounding"] = False
settings
.
add_generation_params
(
p
.
extra_generation_params
)
def
on_mask_blend
(
self
,
p
,
mba
:
scripts
.
MaskBlendArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
def
on_mask_blend
(
self
,
p
,
mba
:
scripts
.
MaskBlendArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
if
not
enabled
:
return
...
...
@@ -675,7 +680,8 @@ class Script(scripts.Script):
mba
.
current_latent
,
get_modified_nmask
(
settings
,
mba
.
nmask
,
mba
.
sigma
[
0
]))
def
post_sample
(
self
,
p
,
ps
:
scripts
.
PostSampleArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
def
post_sample
(
self
,
p
,
ps
:
scripts
.
PostSampleArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
if
not
enabled
:
return
...
...
@@ -723,8 +729,8 @@ class Script(scripts.Script):
height
=
p
.
height
,
paste_to
=
p
.
paste_to
)
def
postprocess_maskoverlay
(
self
,
p
,
ppmo
:
scripts
.
PostProcessMaskOverlayArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
def
postprocess_maskoverlay
(
self
,
p
,
ppmo
:
scripts
.
PostProcessMaskOverlayArgs
,
enabled
,
power
,
scale
,
detail_preservation
,
mask_inf
,
dif_thresh
,
dif_contr
):
if
not
enabled
:
return
...
...
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