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
90a14aa4
Commit
90a14aa4
authored
May 22, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster unpooling for 2x2 zero filled
parent
9aa390c7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
tensorpack/models/_test.py
tensorpack/models/_test.py
+2
-0
tensorpack/models/pool.py
tensorpack/models/pool.py
+29
-7
tensorpack/utils/logger.py
tensorpack/utils/logger.py
+3
-0
No files found.
tensorpack/models/_test.py
View file @
90a14aa4
...
...
@@ -29,6 +29,8 @@ def run_test_case(case):
if
__name__
==
'__main__'
:
import
tensorpack
from
tensorpack.utils
import
logger
logger
.
disable_logger
()
subs
=
tensorpack
.
models
.
_test
.
TestModel
.
__subclasses__
()
for
cls
in
subs
:
run_test_case
(
cls
)
...
...
tensorpack/models/pool.py
View file @
90a14aa4
...
...
@@ -63,6 +63,19 @@ def GlobalAvgPooling(x):
assert
x
.
get_shape
()
.
ndims
==
4
return
tf
.
reduce_mean
(
x
,
[
1
,
2
])
# https://github.com/tensorflow/tensorflow/issues/2169
def
UnPooling2x2ZeroFilled
(
x
):
out
=
tf
.
concat
(
3
,
[
x
,
tf
.
zeros_like
(
x
)])
out
=
tf
.
concat
(
2
,
[
out
,
tf
.
zeros_like
(
out
)])
sh
=
x
.
get_shape
()
.
as_list
()
if
None
not
in
sh
[
1
:]:
out_size
=
[
-
1
,
sh
[
1
]
*
2
,
sh
[
2
]
*
2
,
sh
[
3
]]
return
tf
.
reshape
(
out
,
out_size
)
else
:
sh
=
tf
.
shape
(
x
)
return
tf
.
reshape
(
out
,
[
-
1
,
sh
[
1
]
*
2
,
sh
[
2
]
*
2
,
sh
[
3
]])
@
layer_register
()
def
FixedUnPooling
(
x
,
shape
,
unpool_mat
=
None
):
"""
...
...
@@ -75,6 +88,11 @@ def FixedUnPooling(x, shape, unpool_mat=None):
:returns: NHWC tensor
"""
shape
=
shape2d
(
shape
)
# a faster implementation for this special case
if
shape
[
0
]
==
2
and
shape
[
1
]
==
2
and
unpool_mat
is
None
:
return
UnPooling2x2ZeroFilled
(
x
)
input_shape
=
tf
.
shape
(
x
)
if
unpool_mat
is
None
:
mat
=
np
.
zeros
(
shape
,
dtype
=
'float32'
)
...
...
@@ -136,18 +154,18 @@ from ._test import TestModel
class
TestPool
(
TestModel
):
def
test_fixed_unpooling
(
self
):
h
,
w
=
3
,
4
mat
=
np
.
random
.
rand
(
h
,
w
)
.
astype
(
'float32'
)
mat
=
np
.
random
.
rand
(
h
,
w
,
3
)
.
astype
(
'float32'
)
inp
=
self
.
make_variable
(
mat
)
inp
=
tf
.
reshape
(
inp
,
[
1
,
h
,
w
,
1
])
inp
=
tf
.
reshape
(
inp
,
[
1
,
h
,
w
,
3
])
output
=
FixedUnPooling
(
'unpool'
,
inp
,
2
)
res
=
self
.
run_variable
(
output
)
self
.
assertEqual
(
res
.
shape
,
(
1
,
2
*
h
,
2
*
w
,
1
))
self
.
assertEqual
(
res
.
shape
,
(
1
,
2
*
h
,
2
*
w
,
3
))
# mat is on cornser
ele
=
res
[
0
,::
2
,::
2
,
0
]
self
.
assertTrue
((
ele
==
mat
)
.
all
())
self
.
assertTrue
((
ele
==
mat
[:,:,
0
]
)
.
all
())
# the rest are zeros
res
[
0
,::
2
,::
2
,
0
]
=
0
res
[
0
,::
2
,::
2
,
:
]
=
0
self
.
assertTrue
((
res
==
0
)
.
all
())
def
test_upsample
(
self
):
...
...
@@ -166,6 +184,10 @@ class TestPool(TestModel):
diff
=
np
.
abs
(
res2
-
res
[
0
,:,:,
0
])
# not equivalent at corner
diff
[
0
,
0
]
=
diff
[
-
1
,
-
1
]
=
0
# not equivalent to rescale on edge
diff
[
0
,:]
=
0
diff
[:,
0
]
=
0
if
not
diff
.
max
()
<
1e-4
:
import
IPython
;
IPython
.
embed
(
config
=
IPython
.
terminal
.
ipapp
.
load_default_config
())
self
.
assertTrue
(
diff
.
max
()
<
1e-4
)
tensorpack/utils/logger.py
View file @
90a14aa4
...
...
@@ -95,6 +95,9 @@ unless you're resuming from a previous task.""".format(dirname))
LOG_FILE
=
os
.
path
.
join
(
dirname
,
'log.log'
)
_set_file
(
LOG_FILE
)
def
disable_logger
():
for
func
in
[
'info'
,
'warning'
,
'error'
,
'critical'
,
'warn'
,
'exception'
,
'debug'
]:
globals
()[
func
]
=
lambda
x
:
None
# export logger functions
for
func
in
[
'info'
,
'warning'
,
'error'
,
'critical'
,
'warn'
,
'exception'
,
'debug'
]:
...
...
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