Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Max Ehrlich
cdcnn
Commits
42ad5fb3
Verified
Commit
42ad5fb3
authored
Dec 04, 2018
by
Max Ehrlich
Browse files
Correct handling of blocks with different input and output channels
parent
f70d43ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
models/blocks.py
View file @
42ad5fb3
...
@@ -17,8 +17,11 @@ class SpatialResBlock(nn.Module):
...
@@ -17,8 +17,11 @@ class SpatialResBlock(nn.Module):
self
.
bn2
=
nn
.
BatchNorm2d
(
out_channels
)
self
.
bn2
=
nn
.
BatchNorm2d
(
out_channels
)
self
.
relu
=
nn
.
ReLU
(
inplace
=
True
)
self
.
relu
=
nn
.
ReLU
(
inplace
=
True
)
if
downsample
:
if
downsample
or
in_channels
!=
out_channels
:
self
.
downsampler
=
nn
.
Conv2d
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
,
stride
=
2
,
padding
=
0
,
bias
=
False
)
stride
=
2
if
downsample
else
1
self
.
downsampler
=
nn
.
Conv2d
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
,
stride
=
stride
,
padding
=
0
,
bias
=
False
)
else
:
self
.
downsampler
=
None
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
out
=
self
.
conv1
(
x
)
out
=
self
.
conv1
(
x
)
...
@@ -28,7 +31,7 @@ class SpatialResBlock(nn.Module):
...
@@ -28,7 +31,7 @@ class SpatialResBlock(nn.Module):
out
=
self
.
conv2
(
out
)
out
=
self
.
conv2
(
out
)
out
=
self
.
bn2
(
out
)
out
=
self
.
bn2
(
out
)
if
self
.
downsample
:
if
self
.
downsample
r
is
not
None
:
residual
=
self
.
downsampler
(
x
)
residual
=
self
.
downsampler
(
x
)
else
:
else
:
residual
=
x
residual
=
x
...
@@ -53,11 +56,10 @@ class JpegResBlock(nn.Module):
...
@@ -53,11 +56,10 @@ class JpegResBlock(nn.Module):
self
.
relu
=
jpeg_layers
.
ReLU
(
n_freqs
=
n_freqs
)
self
.
relu
=
jpeg_layers
.
ReLU
(
n_freqs
=
n_freqs
)
if
spatial_resblock
.
downsample
:
if
spatial_resblock
.
downsampler
is
not
None
:
self
.
downsample
=
True
self
.
downsampler
=
jpeg_layers
.
Conv2dRT
(
spatial_resblock
.
downsampler
,
J_down
)
self
.
downsampler
=
jpeg_layers
.
Conv2dRT
(
spatial_resblock
.
downsampler
,
J_down
)
else
:
else
:
self
.
downsample
=
Fals
e
self
.
downsample
r
=
Non
e
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
out
=
self
.
conv1
(
x
)
out
=
self
.
conv1
(
x
)
...
@@ -67,7 +69,7 @@ class JpegResBlock(nn.Module):
...
@@ -67,7 +69,7 @@ class JpegResBlock(nn.Module):
out
=
self
.
conv2
(
out
)
out
=
self
.
conv2
(
out
)
out
=
self
.
bn2
(
out
)
out
=
self
.
bn2
(
out
)
if
self
.
downsample
:
if
self
.
downsample
r
is
not
None
:
residual
=
self
.
downsampler
(
x
)
residual
=
self
.
downsampler
(
x
)
else
:
else
:
residual
=
x
residual
=
x
...
...
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