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
bf67a5dc
Commit
bf67a5dc
authored
May 29, 2023
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upscaler.load_model: don't return None, just use exceptions
parent
e3a973a6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
64 deletions
+52
-64
extensions-builtin/LDSR/scripts/ldsr_model.py
extensions-builtin/LDSR/scripts/ldsr_model.py
+5
-8
extensions-builtin/ScuNET/scripts/scunet_model.py
extensions-builtin/ScuNET/scripts/scunet_model.py
+6
-10
extensions-builtin/SwinIR/scripts/swinir_model.py
extensions-builtin/SwinIR/scripts/swinir_model.py
+20
-20
modules/esrgan_model.py
modules/esrgan_model.py
+6
-8
modules/realesrgan_model.py
modules/realesrgan_model.py
+15
-18
No files found.
extensions-builtin/LDSR/scripts/ldsr_model.py
View file @
bf67a5dc
...
...
@@ -46,16 +46,13 @@ class UpscalerLDSR(Upscaler):
yaml
=
local_yaml_path
or
load_file_from_url
(
self
.
yaml_url
,
model_dir
=
self
.
model_download_path
,
file_name
=
"project.yaml"
)
try
:
return
LDSR
(
model
,
yaml
)
except
Exception
:
errors
.
report
(
"Error importing LDSR"
,
exc_info
=
True
)
return
None
return
LDSR
(
model
,
yaml
)
def
do_upscale
(
self
,
img
,
path
):
ldsr
=
self
.
load_model
(
path
)
if
ldsr
is
None
:
print
(
"NO LDSR!"
)
try
:
ldsr
=
self
.
load_model
(
path
)
except
Exception
:
errors
.
report
(
f
"Failed loading LDSR model {path}"
,
exc_info
=
True
)
return
img
ddim_steps
=
shared
.
opts
.
ldsr_steps
return
ldsr
.
super_resolution
(
img
,
ddim_steps
,
self
.
scale
)
...
...
extensions-builtin/ScuNET/scripts/scunet_model.py
View file @
bf67a5dc
import
os.path
import
sys
import
PIL.Image
...
...
@@ -8,7 +7,7 @@ from tqdm import tqdm
import
modules.upscaler
from
modules
import
devices
,
modelloader
,
script_callbacks
,
errors
from
scunet_model_arch
import
SCUNet
as
net
from
scunet_model_arch
import
SCUNet
from
modules.modelloader
import
load_file_from_url
from
modules.shared
import
opts
...
...
@@ -88,9 +87,10 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
torch
.
cuda
.
empty_cache
()
model
=
self
.
load_model
(
selected_file
)
if
model
is
None
:
print
(
f
"ScuNET: Unable to load model from {selected_file}"
,
file
=
sys
.
stderr
)
try
:
model
=
self
.
load_model
(
selected_file
)
except
Exception
as
e
:
print
(
f
"ScuNET: Unable to load model from {selected_file}: {e}"
,
file
=
sys
.
stderr
)
return
img
device
=
devices
.
get_device_for
(
'scunet'
)
...
...
@@ -123,11 +123,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
filename
=
load_file_from_url
(
self
.
model_url
,
model_dir
=
self
.
model_download_path
,
file_name
=
f
"{self.name}.pth"
)
else
:
filename
=
path
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
model_path
,
filename
))
or
filename
is
None
:
print
(
f
"ScuNET: Unable to load model from {filename}"
,
file
=
sys
.
stderr
)
return
None
model
=
net
(
in_nc
=
3
,
config
=
[
4
,
4
,
4
,
4
,
4
,
4
,
4
],
dim
=
64
)
model
=
SCUNet
(
in_nc
=
3
,
config
=
[
4
,
4
,
4
,
4
,
4
,
4
,
4
],
dim
=
64
)
model
.
load_state_dict
(
torch
.
load
(
filename
),
strict
=
True
)
model
.
eval
()
for
_
,
v
in
model
.
named_parameters
():
...
...
extensions-builtin/SwinIR/scripts/swinir_model.py
View file @
bf67a5dc
import
o
s
import
sy
s
import
numpy
as
np
import
torch
...
...
@@ -7,8 +7,8 @@ from tqdm import tqdm
from
modules
import
modelloader
,
devices
,
script_callbacks
,
shared
from
modules.shared
import
opts
,
state
from
swinir_model_arch
import
SwinIR
as
net
from
swinir_model_arch_v2
import
Swin2SR
as
net2
from
swinir_model_arch
import
SwinIR
from
swinir_model_arch_v2
import
Swin2SR
from
modules.upscaler
import
Upscaler
,
UpscalerData
...
...
@@ -36,8 +36,10 @@ class UpscalerSwinIR(Upscaler):
self
.
scalers
=
scalers
def
do_upscale
(
self
,
img
,
model_file
):
model
=
self
.
load_model
(
model_file
)
if
model
is
None
:
try
:
model
=
self
.
load_model
(
model_file
)
except
Exception
as
e
:
print
(
f
"Failed loading SwinIR model {model_file}: {e}"
,
file
=
sys
.
stderr
)
return
img
model
=
model
.
to
(
device_swinir
,
dtype
=
devices
.
dtype
)
img
=
upscale
(
img
,
model
)
...
...
@@ -56,25 +58,23 @@ class UpscalerSwinIR(Upscaler):
)
else
:
filename
=
path
if
filename
is
None
or
not
os
.
path
.
exists
(
filename
):
return
None
if
filename
.
endswith
(
".v2.pth"
):
model
=
net2
(
upscale
=
scale
,
in_chans
=
3
,
img_size
=
64
,
window_size
=
8
,
img_range
=
1.0
,
depths
=
[
6
,
6
,
6
,
6
,
6
,
6
],
embed_dim
=
180
,
num_heads
=
[
6
,
6
,
6
,
6
,
6
,
6
],
mlp_ratio
=
2
,
upsampler
=
"nearest+conv"
,
resi_connection
=
"1conv"
,
model
=
Swin2SR
(
upscale
=
scale
,
in_chans
=
3
,
img_size
=
64
,
window_size
=
8
,
img_range
=
1.0
,
depths
=
[
6
,
6
,
6
,
6
,
6
,
6
],
embed_dim
=
180
,
num_heads
=
[
6
,
6
,
6
,
6
,
6
,
6
],
mlp_ratio
=
2
,
upsampler
=
"nearest+conv"
,
resi_connection
=
"1conv"
,
)
params
=
None
else
:
model
=
net
(
model
=
SwinIR
(
upscale
=
scale
,
in_chans
=
3
,
img_size
=
64
,
...
...
modules/esrgan_model.py
View file @
bf67a5dc
import
o
s
import
sy
s
import
numpy
as
np
import
torch
...
...
@@ -6,9 +6,8 @@ from PIL import Image
import
modules.esrgan_model_arch
as
arch
from
modules
import
modelloader
,
images
,
devices
from
modules.upscaler
import
Upscaler
,
UpscalerData
from
modules.shared
import
opts
from
modules.upscaler
import
Upscaler
,
UpscalerData
def
mod2normal
(
state_dict
):
...
...
@@ -142,8 +141,10 @@ class UpscalerESRGAN(Upscaler):
self
.
scalers
.
append
(
scaler_data
)
def
do_upscale
(
self
,
img
,
selected_model
):
model
=
self
.
load_model
(
selected_model
)
if
model
is
None
:
try
:
model
=
self
.
load_model
(
selected_model
)
except
Exception
as
e
:
print
(
f
"Unable to load ESRGAN model {selected_model}: {e}"
,
file
=
sys
.
stderr
)
return
img
model
.
to
(
devices
.
device_esrgan
)
img
=
esrgan_upscale
(
model
,
img
)
...
...
@@ -159,9 +160,6 @@ class UpscalerESRGAN(Upscaler):
)
else
:
filename
=
path
if
not
os
.
path
.
exists
(
filename
)
or
filename
is
None
:
print
(
f
"Unable to load {self.model_path} from {filename}"
)
return
None
state_dict
=
torch
.
load
(
filename
,
map_location
=
'cpu'
if
devices
.
device_esrgan
.
type
==
'mps'
else
None
)
...
...
modules/realesrgan_model.py
View file @
bf67a5dc
...
...
@@ -9,7 +9,6 @@ from modules.shared import cmd_opts, opts
from
modules
import
modelloader
,
errors
class
UpscalerRealESRGAN
(
Upscaler
):
def
__init__
(
self
,
path
):
self
.
name
=
"RealESRGAN"
...
...
@@ -43,9 +42,10 @@ class UpscalerRealESRGAN(Upscaler):
if
not
self
.
enable
:
return
img
info
=
self
.
load_model
(
path
)
if
not
os
.
path
.
exists
(
info
.
local_data_path
):
print
(
f
"Unable to load RealESRGAN model: {info.name}"
)
try
:
info
=
self
.
load_model
(
path
)
except
Exception
:
errors
.
report
(
f
"Unable to load RealESRGAN model {path}"
,
exc_info
=
True
)
return
img
upsampler
=
RealESRGANer
(
...
...
@@ -63,20 +63,17 @@ class UpscalerRealESRGAN(Upscaler):
return
image
def
load_model
(
self
,
path
):
try
:
info
=
next
(
iter
([
scaler
for
scaler
in
self
.
scalers
if
scaler
.
data_path
==
path
]),
None
)
if
info
is
None
:
print
(
f
"Unable to find model info: {path}"
)
return
None
if
info
.
local_data_path
.
startswith
(
"http"
):
info
.
local_data_path
=
modelloader
.
load_file_from_url
(
info
.
data_path
,
model_dir
=
self
.
model_download_path
)
return
info
except
Exception
:
errors
.
report
(
"Error making Real-ESRGAN models list"
,
exc_info
=
True
)
return
None
for
scaler
in
self
.
scalers
:
if
scaler
.
data_path
==
path
:
if
scaler
.
local_data_path
.
startswith
(
"http"
):
scaler
.
local_data_path
=
modelloader
.
load_file_from_url
(
scaler
.
data_path
,
model_dir
=
self
.
model_download_path
,
)
if
not
os
.
path
.
exists
(
scaler
.
local_data_path
):
raise
FileNotFoundError
(
f
"RealESRGAN data missing: {scaler.local_data_path}"
)
return
scaler
raise
ValueError
(
f
"Unable to find model info: {path}"
)
def
load_models
(
self
,
_
):
return
get_realesrgan_models
(
self
)
...
...
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