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
4ad0c0c0
Commit
4ad0c0c0
authored
Dec 30, 2023
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify architecture for loaded Spandrel models
parent
c7561335
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
5 deletions
+22
-5
extensions-builtin/ScuNET/scripts/scunet_model.py
extensions-builtin/ScuNET/scripts/scunet_model.py
+1
-1
extensions-builtin/SwinIR/scripts/swinir_model.py
extensions-builtin/SwinIR/scripts/swinir_model.py
+1
-0
modules/codeformer_model.py
modules/codeformer_model.py
+1
-0
modules/esrgan_model.py
modules/esrgan_model.py
+1
-0
modules/gfpgan_model.py
modules/gfpgan_model.py
+1
-0
modules/hat_model.py
modules/hat_model.py
+1
-0
modules/modelloader.py
modules/modelloader.py
+12
-1
modules/realesrgan_model.py
modules/realesrgan_model.py
+4
-3
No files found.
extensions-builtin/ScuNET/scripts/scunet_model.py
View file @
4ad0c0c0
...
...
@@ -121,7 +121,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
filename
=
modelloader
.
load_file_from_url
(
self
.
model_url
,
model_dir
=
self
.
model_download_path
,
file_name
=
f
"{self.name}.pth"
)
else
:
filename
=
path
return
modelloader
.
load_spandrel_model
(
filename
,
device
=
device
)
return
modelloader
.
load_spandrel_model
(
filename
,
device
=
device
,
expected_architecture
=
'SCUNet'
)
def
on_ui_settings
():
...
...
extensions-builtin/SwinIR/scripts/swinir_model.py
View file @
4ad0c0c0
...
...
@@ -75,6 +75,7 @@ class UpscalerSwinIR(Upscaler):
filename
,
device
=
self
.
_get_device
(),
dtype
=
devices
.
dtype
,
expected_architecture
=
"SwinIR"
,
)
if
getattr
(
opts
,
'SWIN_torch_compile'
,
False
):
try
:
...
...
modules/codeformer_model.py
View file @
4ad0c0c0
...
...
@@ -37,6 +37,7 @@ class FaceRestorerCodeFormer(face_restoration_utils.CommonFaceRestoration):
return
modelloader
.
load_spandrel_model
(
model_path
,
device
=
devices
.
device_codeformer
,
expected_architecture
=
'CodeFormer'
,
)
.
model
raise
ValueError
(
"No codeformer model found"
)
...
...
modules/esrgan_model.py
View file @
4ad0c0c0
...
...
@@ -49,6 +49,7 @@ class UpscalerESRGAN(Upscaler):
return
modelloader
.
load_spandrel_model
(
filename
,
device
=
(
'cpu'
if
devices
.
device_esrgan
.
type
==
'mps'
else
None
),
expected_architecture
=
'ESRGAN'
,
)
...
...
modules/gfpgan_model.py
View file @
4ad0c0c0
...
...
@@ -37,6 +37,7 @@ class FaceRestorerGFPGAN(face_restoration_utils.CommonFaceRestoration):
net
=
modelloader
.
load_spandrel_model
(
model_path
,
device
=
self
.
get_device
(),
expected_architecture
=
'GFPGAN'
,
)
.
model
net
.
different_w
=
True
# see https://github.com/chaiNNer-org/spandrel/pull/81
return
net
...
...
modules/hat_model.py
View file @
4ad0c0c0
...
...
@@ -39,4 +39,5 @@ class UpscalerHAT(Upscaler):
return
modelloader
.
load_spandrel_model
(
path
,
device
=
devices
.
device_esrgan
,
# TODO: should probably be device_hat
expected_architecture
=
'HAT'
,
)
modules/modelloader.py
View file @
4ad0c0c0
...
...
@@ -6,6 +6,8 @@ import shutil
import
importlib
from
urllib.parse
import
urlparse
import
torch
from
modules
import
shared
from
modules.upscaler
import
Upscaler
,
UpscalerLanczos
,
UpscalerNearest
,
UpscalerNone
from
modules.paths
import
script_path
,
models_path
...
...
@@ -183,9 +185,18 @@ def load_upscalers():
)
def
load_spandrel_model
(
path
,
*
,
device
,
half
:
bool
=
False
,
dtype
=
None
):
def
load_spandrel_model
(
path
:
str
,
*
,
device
:
str
|
torch
.
device
|
None
,
half
:
bool
=
False
,
dtype
:
str
|
None
=
None
,
expected_architecture
:
str
|
None
=
None
,
):
import
spandrel
model
=
spandrel
.
ModelLoader
(
device
=
device
)
.
load_from_file
(
path
)
if
expected_architecture
and
model
.
architecture
!=
expected_architecture
:
raise
TypeError
(
f
"Model {path} is not a {expected_architecture} model"
)
if
half
:
model
=
model
.
model
.
half
()
if
dtype
:
...
...
modules/realesrgan_model.py
View file @
4ad0c0c0
import
os
from
modules.upscaler_utils
import
upscale_with_model
from
modules.upscaler
import
Upscaler
,
UpscalerData
from
modules.shared
import
cmd_opts
,
opts
from
modules
import
modelloader
,
errors
from
modules.shared
import
cmd_opts
,
opts
from
modules.upscaler
import
Upscaler
,
UpscalerData
from
modules.upscaler_utils
import
upscale_with_model
class
UpscalerRealESRGAN
(
Upscaler
):
...
...
@@ -40,6 +40,7 @@ class UpscalerRealESRGAN(Upscaler):
info
.
local_data_path
,
device
=
self
.
device
,
half
=
(
not
cmd_opts
.
no_half
and
not
cmd_opts
.
upcast_sampling
),
expected_architecture
=
"RealESRGAN"
,
)
return
upscale_with_model
(
mod
,
...
...
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