Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
aaf7eeda
Commit
aaf7eeda
authored
Nov 09, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deconv
parent
1db8e2b4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
tensorpack/models/conv2d.py
tensorpack/models/conv2d.py
+48
-3
tensorpack/models/fc.py
tensorpack/models/fc.py
+1
-1
No files found.
tensorpack/models/conv2d.py
View file @
aaf7eeda
...
...
@@ -9,7 +9,7 @@ import math
from
._common
import
layer_register
,
shape2d
,
shape4d
from
..utils
import
map_arg
,
logger
__all__
=
[
'Conv2D'
]
__all__
=
[
'Conv2D'
,
'Deconv2D'
]
@
layer_register
()
def
Conv2D
(
x
,
out_channel
,
kernel_shape
,
...
...
@@ -20,13 +20,14 @@ def Conv2D(x, out_channel, kernel_shape,
2D convolution on 4D inputs.
:param input: a tensor of shape NHWC
:param out_channel: number of output channel
:param kernel_shape: (h, w) or a int
:param stride: (h, w) or a int. default to 1
:param padding: 'valid' or 'same'. default to 'same'
:param split: split channels as used in Alexnet. Default to 1 (no split)
:param W_init: initializer for W. default to `xavier_initializer_conv2d`.
:param b_init: initializer for b. default to zero initializer.
:param nl: nonlinearity
. default to `relu`.
:param nl: nonlinearity
:param use_bias: whether to use bias. a boolean default to True
:returns: a NHWC tensor
"""
...
...
@@ -42,7 +43,6 @@ def Conv2D(x, out_channel, kernel_shape,
stride
=
shape4d
(
stride
)
if
W_init
is
None
:
#W_init = tf.truncated_normal_initializer(stddev=3e-2)
W_init
=
tf
.
contrib
.
layers
.
xavier_initializer_conv2d
()
if
b_init
is
None
:
b_init
=
tf
.
constant_initializer
()
...
...
@@ -64,3 +64,48 @@ def Conv2D(x, out_channel, kernel_shape,
nl
=
tf
.
nn
.
relu
return
nl
(
tf
.
nn
.
bias_add
(
conv
,
b
)
if
use_bias
else
conv
,
name
=
'output'
)
@
layer_register
()
def
Deconv2D
(
x
,
out_shape
,
kernel_shape
,
stride
,
padding
=
'SAME'
,
W_init
=
None
,
b_init
=
None
,
nl
=
tf
.
identity
,
use_bias
=
True
):
"""
2D deconvolution on 4D inputs.
:param input: a tensor of shape NHWC
:param out_shape: either (h, w, channel), or just channel,
then h, w will calculated by input_shape * stride
:param kernel_shape: (h, w) or a int
:param stride: (h, w) or a int
:param padding: 'valid' or 'same'. default to 'same'
:param W_init: initializer for W. default to `xavier_initializer_conv2d`.
:param b_init: initializer for b. default to zero initializer.
:param nl: nonlinearity.
:param use_bias: whether to use bias. a boolean default to True
:returns: a NHWC tensor
"""
in_shape
=
x
.
get_shape
()
.
as_list
()[
1
:]
assert
None
is
not
in
in_shape
,
"Input to Deconv2D cannot have unknown shape!"
in_channel
=
in_shape
[
-
1
]
kernel_shape
=
shape2d
(
kernel_shape
)
stride2d
=
shape2d
(
stride
)
stride4d
=
shape4d
(
stride
)
padding
=
padding
.
upper
()
filter_shape
=
kernel_shape
+
[
in_channel
,
out_channel
]
if
isinstance
(
out_shape
,
int
):
out_shape
=
tf
.
pack
([
tf
.
shape
(
x
)[
0
],
stride2d
[
0
]
*
in_shape
[
0
],
stride2d
[
1
]
*
in_shape
[
1
],
out_shape
])
else
:
out_shape
=
tf
.
pack
([
tf
.
shape
(
x
)[
0
]]
+
out_shape
)
if
W_init
is
None
:
W_init
=
tf
.
contrib
.
layers
.
xavier_initializer_conv2d
()
if
b_init
is
None
:
b_init
=
tf
.
constant_initializer
()
W
=
tf
.
get_variable
(
'W'
,
filter_shape
,
initializer
=
W_init
)
if
use_bias
:
b
=
tf
.
get_variable
(
'b'
,
[
out_channel
],
initializer
=
b_init
)
conv
=
tf
.
nn
.
conv2d_transpose
(
x
,
W
,
out_shape
,
stride4d
,
padding
=
padding
)
return
nl
(
tf
.
nn
.
bias_add
(
conv
,
b
)
if
use_bias
else
conv
,
name
=
'output'
)
tensorpack/models/fc.py
View file @
aaf7eeda
...
...
@@ -22,7 +22,7 @@ def FullyConnected(x, out_dim,
:param out_dim: output dimension
:param W_init: initializer for W. default to `xavier_initializer_conv2d`.
:param b_init: initializer for b. default to zero initializer.
:param nl: nonlinearity
. default to `relu`.
:param nl: nonlinearity
:param use_bias: whether to use bias. a boolean default to True
:returns: a 2D tensor
"""
...
...
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