Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
e359268b
Unverified
Commit
e359268b
authored
Nov 02, 2022
by
AUTOMATIC1111
Committed by
GitHub
Nov 02, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3976 from victorca25/esrgan_fea
multiple trivial changes for "extras" models
parents
bb21a4cb
c9bb33dd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
6 deletions
+33
-6
esrgan_model.py
modules/esrgan_model.py
+13
-4
modelloader.py
modules/modelloader.py
+3
-0
ui.py
modules/ui.py
+1
-1
upscaler.py
modules/upscaler.py
+16
-1
No files found.
modules/esrgan_model.py
View file @
e359268b
...
...
@@ -50,6 +50,7 @@ def mod2normal(state_dict):
def
resrgan2normal
(
state_dict
,
nb
=
23
):
# this code is copied from https://github.com/victorca25/iNNfer
if
"conv_first.weight"
in
state_dict
and
"body.0.rdb1.conv1.weight"
in
state_dict
:
re8x
=
0
crt_net
=
{}
items
=
[]
for
k
,
v
in
state_dict
.
items
():
...
...
@@ -75,10 +76,18 @@ def resrgan2normal(state_dict, nb=23):
crt_net
[
'model.3.bias'
]
=
state_dict
[
'conv_up1.bias'
]
crt_net
[
'model.6.weight'
]
=
state_dict
[
'conv_up2.weight'
]
crt_net
[
'model.6.bias'
]
=
state_dict
[
'conv_up2.bias'
]
crt_net
[
'model.8.weight'
]
=
state_dict
[
'conv_hr.weight'
]
crt_net
[
'model.8.bias'
]
=
state_dict
[
'conv_hr.bias'
]
crt_net
[
'model.10.weight'
]
=
state_dict
[
'conv_last.weight'
]
crt_net
[
'model.10.bias'
]
=
state_dict
[
'conv_last.bias'
]
if
'conv_up3.weight'
in
state_dict
:
# modification supporting: https://github.com/ai-forever/Real-ESRGAN/blob/main/RealESRGAN/rrdbnet_arch.py
re8x
=
3
crt_net
[
'model.9.weight'
]
=
state_dict
[
'conv_up3.weight'
]
crt_net
[
'model.9.bias'
]
=
state_dict
[
'conv_up3.bias'
]
crt_net
[
f
'model.{8+re8x}.weight'
]
=
state_dict
[
'conv_hr.weight'
]
crt_net
[
f
'model.{8+re8x}.bias'
]
=
state_dict
[
'conv_hr.bias'
]
crt_net
[
f
'model.{10+re8x}.weight'
]
=
state_dict
[
'conv_last.weight'
]
crt_net
[
f
'model.{10+re8x}.bias'
]
=
state_dict
[
'conv_last.bias'
]
state_dict
=
crt_net
return
state_dict
...
...
modules/modelloader.py
View file @
e359268b
...
...
@@ -85,6 +85,9 @@ def cleanup_models():
src_path
=
os
.
path
.
join
(
root_path
,
"ESRGAN"
)
dest_path
=
os
.
path
.
join
(
models_path
,
"ESRGAN"
)
move_files
(
src_path
,
dest_path
)
src_path
=
os
.
path
.
join
(
models_path
,
"BSRGAN"
)
dest_path
=
os
.
path
.
join
(
models_path
,
"ESRGAN"
)
move_files
(
src_path
,
dest_path
,
".pth"
)
src_path
=
os
.
path
.
join
(
root_path
,
"gfpgan"
)
dest_path
=
os
.
path
.
join
(
models_path
,
"GFPGAN"
)
move_files
(
src_path
,
dest_path
)
...
...
modules/ui.py
View file @
e359268b
...
...
@@ -1054,7 +1054,7 @@ def create_ui(wrap_gradio_gpu_call):
with
gr
.
Tabs
(
elem_id
=
"extras_resize_mode"
):
with
gr
.
TabItem
(
'Scale by'
):
upscaling_resize
=
gr
.
Slider
(
minimum
=
1.0
,
maximum
=
4.0
,
step
=
0.05
,
label
=
"Resize"
,
value
=
2
)
upscaling_resize
=
gr
.
Slider
(
minimum
=
1.0
,
maximum
=
8.0
,
step
=
0.05
,
label
=
"Resize"
,
value
=
4
)
with
gr
.
TabItem
(
'Scale to'
):
with
gr
.
Group
():
with
gr
.
Row
():
...
...
modules/upscaler.py
View file @
e359268b
...
...
@@ -10,6 +10,7 @@ import modules.shared
from
modules
import
modelloader
,
shared
LANCZOS
=
(
Image
.
Resampling
.
LANCZOS
if
hasattr
(
Image
,
'Resampling'
)
else
Image
.
LANCZOS
)
NEAREST
=
(
Image
.
Resampling
.
NEAREST
if
hasattr
(
Image
,
'Resampling'
)
else
Image
.
NEAREST
)
from
modules.paths
import
models_path
...
...
@@ -57,7 +58,7 @@ class Upscaler:
dest_w
=
img
.
width
*
scale
dest_h
=
img
.
height
*
scale
for
i
in
range
(
3
):
if
img
.
width
>
=
dest_w
and
img
.
height
>=
dest_h
:
if
img
.
width
>
dest_w
and
img
.
height
>
dest_h
:
break
img
=
self
.
do_upscale
(
img
,
selected_model
)
if
img
.
width
!=
dest_w
or
img
.
height
!=
dest_h
:
...
...
@@ -120,3 +121,17 @@ class UpscalerLanczos(Upscaler):
self
.
name
=
"Lanczos"
self
.
scalers
=
[
UpscalerData
(
"Lanczos"
,
None
,
self
)]
class
UpscalerNearest
(
Upscaler
):
scalers
=
[]
def
do_upscale
(
self
,
img
,
selected_model
=
None
):
return
img
.
resize
((
int
(
img
.
width
*
self
.
scale
),
int
(
img
.
height
*
self
.
scale
)),
resample
=
NEAREST
)
def
load_model
(
self
,
_
):
pass
def
__init__
(
self
,
dirname
=
None
):
super
()
.
__init__
(
False
)
self
.
name
=
"Nearest"
self
.
scalers
=
[
UpscalerData
(
"Nearest"
,
None
,
self
)]
\ No newline at end of file
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