Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
diffusers
Commits
8d7771d8
Commit
8d7771d8
authored
Jul 01, 2022
by
Patrick von Platen
Browse files
make work with first resnet
parent
9da575d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
src/diffusers/models/resnet.py
src/diffusers/models/resnet.py
+7
-6
src/diffusers/models/unet_sde_score_estimation.py
src/diffusers/models/unet_sde_score_estimation.py
+10
-12
No files found.
src/diffusers/models/resnet.py
View file @
8d7771d8
...
@@ -436,10 +436,9 @@ class ResnetBlock(nn.Module):
...
@@ -436,10 +436,9 @@ class ResnetBlock(nn.Module):
self
.
upsample
=
Upsample
(
in_channels
,
use_conv
=
False
,
dims
=
2
)
if
self
.
up
else
None
self
.
upsample
=
Upsample
(
in_channels
,
use_conv
=
False
,
dims
=
2
)
if
self
.
up
else
None
self
.
downsample
=
Downsample
(
in_channels
,
use_conv
=
False
,
dims
=
2
,
padding
=
1
,
name
=
"op"
)
if
self
.
down
else
None
self
.
downsample
=
Downsample
(
in_channels
,
use_conv
=
False
,
dims
=
2
,
padding
=
1
,
name
=
"op"
)
if
self
.
down
else
None
self
.
nin_shortcut
=
use_nin_shortcut
self
.
use_nin_shortcut
=
self
.
in_channels
!=
self
.
out_channels
if
use_nin_shortcut
is
None
else
use_nin_shortcut
if
self
.
use_nin_shortcut
is
None
:
self
.
use_nin_shortcut
=
self
.
in_channels
!=
self
.
out_channels
self
.
nin_shortcut
=
None
if
self
.
use_nin_shortcut
:
if
self
.
use_nin_shortcut
:
self
.
nin_shortcut
=
torch
.
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
self
.
nin_shortcut
=
torch
.
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
...
@@ -526,8 +525,10 @@ class ResnetBlock(nn.Module):
...
@@ -526,8 +525,10 @@ class ResnetBlock(nn.Module):
self
.
out_ch
=
out_ch
self
.
out_ch
=
out_ch
# TODO(Patrick) - move to main init
# TODO(Patrick) - move to main init
self
.
upsample
=
functools
.
partial
(
upsample_2d
,
k
=
self
.
fir_kernel
)
if
self
.
up
:
self
.
downsample
=
functools
.
partial
(
downsample_2d
,
k
=
self
.
fir_kernel
)
self
.
upsample
=
functools
.
partial
(
upsample_2d
,
k
=
self
.
fir_kernel
)
if
self
.
down
:
self
.
downsample
=
functools
.
partial
(
downsample_2d
,
k
=
self
.
fir_kernel
)
self
.
is_overwritten
=
False
self
.
is_overwritten
=
False
...
@@ -647,7 +648,7 @@ class ResnetBlock(nn.Module):
...
@@ -647,7 +648,7 @@ class ResnetBlock(nn.Module):
if
self
.
nin_shortcut
is
not
None
:
if
self
.
nin_shortcut
is
not
None
:
x
=
self
.
nin_shortcut
(
x
)
x
=
self
.
nin_shortcut
(
x
)
return
x
+
h
return
(
x
+
h
)
/
self
.
output_scale_factor
# TODO(Patrick) - just there to convert the weights; can delete afterward
# TODO(Patrick) - just there to convert the weights; can delete afterward
...
...
src/diffusers/models/unet_sde_score_estimation.py
View file @
8d7771d8
...
@@ -348,18 +348,16 @@ class NCSNpp(ModelMixin, ConfigMixin):
...
@@ -348,18 +348,16 @@ class NCSNpp(ModelMixin, ConfigMixin):
for
i_block
in
range
(
num_res_blocks
):
for
i_block
in
range
(
num_res_blocks
):
out_ch
=
nf
*
ch_mult
[
i_level
]
out_ch
=
nf
*
ch_mult
[
i_level
]
# modules.append(ResnetBlock(in_ch=in_ch, out_ch=out_ch))
# modules.append(ResnetBlock(in_ch=in_ch, out_ch=out_ch))
modules
.
append
(
modules
.
append
(
ResnetNew
(
ResnetNew
(
in_channels
=
in_ch
,
in_channels
=
in_ch
,
out_channels
=
out_ch
,
out_channels
=
out_ch
,
temb_channels
=
4
*
nf
,
temb_channels
=
4
*
nf
,
output_scale_factor
=
np
.
sqrt
(
2.0
),
output_scale_factor
=
np
.
sqrt
(
2.0
),
non_linearity
=
"silu"
,
non_linearity
=
"silu"
,
groups
=
min
(
in_ch
//
4
,
32
),
groups
=
min
(
in_ch
//
4
,
32
),
groups_out
=
min
(
out_ch
//
4
,
32
),
groups_out
=
min
(
out_ch
//
4
,
32
),
overwrite_for_score_vde
=
True
,
overwrite_for_score_vde
=
True
,
))
)
)
in_ch
=
out_ch
in_ch
=
out_ch
if
all_resolutions
[
i_level
]
in
attn_resolutions
:
if
all_resolutions
[
i_level
]
in
attn_resolutions
:
...
...
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