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
3f7f61e5
Commit
3f7f61e5
authored
Jan 04, 2024
by
AUTOMATIC1111
Committed by
GitHub
Jan 04, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14524 from akx/fix-swinir-issues
Fix SwinIR issues
parents
1e7a8ce5
62470ee2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
6 deletions
+7
-6
extensions-builtin/SwinIR/scripts/swinir_model.py
extensions-builtin/SwinIR/scripts/swinir_model.py
+3
-2
modules/upscaler_utils.py
modules/upscaler_utils.py
+4
-4
No files found.
extensions-builtin/SwinIR/scripts/swinir_model.py
View file @
3f7f61e5
import
logging
import
logging
import
sys
import
sys
import
torch
from
PIL
import
Image
from
PIL
import
Image
from
modules
import
devices
,
modelloader
,
script_callbacks
,
shared
,
upscaler_utils
from
modules
import
devices
,
modelloader
,
script_callbacks
,
shared
,
upscaler_utils
...
@@ -50,7 +51,7 @@ class UpscalerSwinIR(Upscaler):
...
@@ -50,7 +51,7 @@ class UpscalerSwinIR(Upscaler):
model
,
model
,
tile_size
=
shared
.
opts
.
SWIN_tile
,
tile_size
=
shared
.
opts
.
SWIN_tile
,
tile_overlap
=
shared
.
opts
.
SWIN_tile_overlap
,
tile_overlap
=
shared
.
opts
.
SWIN_tile_overlap
,
scale
=
4
,
# TODO: This was hard-coded before too...
scale
=
model
.
scale
,
desc
=
"SwinIR"
,
desc
=
"SwinIR"
,
)
)
devices
.
torch_gc
()
devices
.
torch_gc
()
...
@@ -69,7 +70,7 @@ class UpscalerSwinIR(Upscaler):
...
@@ -69,7 +70,7 @@ class UpscalerSwinIR(Upscaler):
model_descriptor
=
modelloader
.
load_spandrel_model
(
model_descriptor
=
modelloader
.
load_spandrel_model
(
filename
,
filename
,
device
=
self
.
_get_device
(),
device
=
self
.
_get_device
(),
dtype
=
devices
.
dtype
,
prefer_half
=
(
devices
.
dtype
==
torch
.
float16
)
,
expected_architecture
=
"SwinIR"
,
expected_architecture
=
"SwinIR"
,
)
)
if
getattr
(
shared
.
opts
,
'SWIN_torch_compile'
,
False
):
if
getattr
(
shared
.
opts
,
'SWIN_torch_compile'
,
False
):
...
...
modules/upscaler_utils.py
View file @
3f7f61e5
...
@@ -94,6 +94,7 @@ def tiled_upscale_2(
...
@@ -94,6 +94,7 @@ def tiled_upscale_2(
tile_size
:
int
,
tile_size
:
int
,
tile_overlap
:
int
,
tile_overlap
:
int
,
scale
:
int
,
scale
:
int
,
device
:
torch
.
device
,
desc
=
"Tiled upscale"
,
desc
=
"Tiled upscale"
,
):
):
# Alternative implementation of `upscale_with_model` originally used by
# Alternative implementation of `upscale_with_model` originally used by
...
@@ -101,9 +102,6 @@ def tiled_upscale_2(
...
@@ -101,9 +102,6 @@ def tiled_upscale_2(
# weighting is done in PyTorch space, as opposed to `images.Grid` doing it in
# weighting is done in PyTorch space, as opposed to `images.Grid` doing it in
# Pillow space without weighting.
# Pillow space without weighting.
# Grab the device the model is on, and use it.
device
=
torch_utils
.
get_param
(
model
)
.
device
b
,
c
,
h
,
w
=
img
.
size
()
b
,
c
,
h
,
w
=
img
.
size
()
tile_size
=
min
(
tile_size
,
h
,
w
)
tile_size
=
min
(
tile_size
,
h
,
w
)
...
@@ -175,7 +173,8 @@ def upscale_2(
...
@@ -175,7 +173,8 @@ def upscale_2(
"""
"""
Convenience wrapper around `tiled_upscale_2` that handles PIL images.
Convenience wrapper around `tiled_upscale_2` that handles PIL images.
"""
"""
tensor
=
pil_image_to_torch_bgr
(
img
)
.
float
()
.
unsqueeze
(
0
)
# add batch dimension
param
=
torch_utils
.
get_param
(
model
)
tensor
=
pil_image_to_torch_bgr
(
img
)
.
to
(
dtype
=
param
.
dtype
)
.
unsqueeze
(
0
)
# add batch dimension
with
torch
.
no_grad
():
with
torch
.
no_grad
():
output
=
tiled_upscale_2
(
output
=
tiled_upscale_2
(
...
@@ -185,5 +184,6 @@ def upscale_2(
...
@@ -185,5 +184,6 @@ def upscale_2(
tile_overlap
=
tile_overlap
,
tile_overlap
=
tile_overlap
,
scale
=
scale
,
scale
=
scale
,
desc
=
desc
,
desc
=
desc
,
device
=
param
.
device
,
)
)
return
torch_bgr_to_pil_image
(
output
)
return
torch_bgr_to_pil_image
(
output
)
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