Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
8be46438
Commit
8be46438
authored
Sep 07, 2023
by
comfyanonymous
Browse files
Support DiffBIR SwinIR models.
parent
cb080e77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletion
+18
-1
comfy_extras/chainner_models/architecture/SwinIR.py
comfy_extras/chainner_models/architecture/SwinIR.py
+16
-1
comfy_extras/nodes_upscale_model.py
comfy_extras/nodes_upscale_model.py
+2
-0
No files found.
comfy_extras/chainner_models/architecture/SwinIR.py
View file @
8be46438
...
...
@@ -846,6 +846,7 @@ class SwinIR(nn.Module):
num_in_ch
=
in_chans
num_out_ch
=
in_chans
supports_fp16
=
True
self
.
start_unshuffle
=
1
self
.
model_arch
=
"SwinIR"
self
.
sub_type
=
"SR"
...
...
@@ -874,6 +875,11 @@ class SwinIR(nn.Module):
else
64
)
if
"conv_first.1.weight"
in
self
.
state
:
self
.
state
[
"conv_first.weight"
]
=
self
.
state
.
pop
(
"conv_first.1.weight"
)
self
.
state
[
"conv_first.bias"
]
=
self
.
state
.
pop
(
"conv_first.1.bias"
)
self
.
start_unshuffle
=
round
(
math
.
sqrt
(
self
.
state
[
"conv_first.weight"
].
shape
[
1
]
//
3
))
num_in_ch
=
self
.
state
[
"conv_first.weight"
].
shape
[
1
]
in_chans
=
num_in_ch
if
"conv_last.weight"
in
state_keys
:
...
...
@@ -968,7 +974,7 @@ class SwinIR(nn.Module):
self
.
depths
=
depths
self
.
window_size
=
window_size
self
.
mlp_ratio
=
mlp_ratio
self
.
scale
=
upscale
self
.
scale
=
upscale
/
self
.
start_unshuffle
self
.
upsampler
=
upsampler
self
.
img_size
=
img_size
self
.
img_range
=
img_range
...
...
@@ -1101,6 +1107,9 @@ class SwinIR(nn.Module):
self
.
conv_up1
=
nn
.
Conv2d
(
num_feat
,
num_feat
,
3
,
1
,
1
)
if
self
.
upscale
==
4
:
self
.
conv_up2
=
nn
.
Conv2d
(
num_feat
,
num_feat
,
3
,
1
,
1
)
elif
self
.
upscale
==
8
:
self
.
conv_up2
=
nn
.
Conv2d
(
num_feat
,
num_feat
,
3
,
1
,
1
)
self
.
conv_up3
=
nn
.
Conv2d
(
num_feat
,
num_feat
,
3
,
1
,
1
)
self
.
conv_hr
=
nn
.
Conv2d
(
num_feat
,
num_feat
,
3
,
1
,
1
)
self
.
conv_last
=
nn
.
Conv2d
(
num_feat
,
num_out_ch
,
3
,
1
,
1
)
self
.
lrelu
=
nn
.
LeakyReLU
(
negative_slope
=
0.2
,
inplace
=
True
)
...
...
@@ -1157,6 +1166,9 @@ class SwinIR(nn.Module):
self
.
mean
=
self
.
mean
.
type_as
(
x
)
x
=
(
x
-
self
.
mean
)
*
self
.
img_range
if
self
.
start_unshuffle
>
1
:
x
=
torch
.
nn
.
functional
.
pixel_unshuffle
(
x
,
self
.
start_unshuffle
)
if
self
.
upsampler
==
"pixelshuffle"
:
# for classical SR
x
=
self
.
conv_first
(
x
)
...
...
@@ -1186,6 +1198,9 @@ class SwinIR(nn.Module):
)
)
)
elif
self
.
upscale
==
8
:
x
=
self
.
lrelu
(
self
.
conv_up2
(
torch
.
nn
.
functional
.
interpolate
(
x
,
scale_factor
=
2
,
mode
=
'nearest'
)))
x
=
self
.
lrelu
(
self
.
conv_up3
(
torch
.
nn
.
functional
.
interpolate
(
x
,
scale_factor
=
2
,
mode
=
'nearest'
)))
x
=
self
.
conv_last
(
self
.
lrelu
(
self
.
conv_hr
(
x
)))
else
:
# for image denoising and JPEG compression artifact reduction
...
...
comfy_extras/nodes_upscale_model.py
View file @
8be46438
...
...
@@ -18,6 +18,8 @@ class UpscaleModelLoader:
def
load_model
(
self
,
model_name
):
model_path
=
folder_paths
.
get_full_path
(
"upscale_models"
,
model_name
)
sd
=
comfy
.
utils
.
load_torch_file
(
model_path
,
safe_load
=
True
)
if
"module.layers.0.residual_group.blocks.0.norm1.weight"
in
sd
:
sd
=
comfy
.
utils
.
state_dict_prefix_replace
(
sd
,
{
"module."
:
""
})
out
=
model_loading
.
load_state_dict
(
sd
).
eval
()
return
(
out
,
)
...
...
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