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
ac6e140f
You need to sign in or sign up before continuing.
Commit
ac6e140f
authored
May 10, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upsample layer
parent
67cfcdee
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
9 deletions
+69
-9
scripts/dump_train_config.py
scripts/dump_train_config.py
+3
-2
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+2
-2
tensorpack/dataflow/dataset/bsds500.py
tensorpack/dataflow/dataset/bsds500.py
+3
-2
tensorpack/dataflow/format.py
tensorpack/dataflow/format.py
+1
-1
tensorpack/dataflow/imgaug/base.py
tensorpack/dataflow/imgaug/base.py
+1
-0
tensorpack/dataflow/prefetch.py
tensorpack/dataflow/prefetch.py
+1
-1
tensorpack/models/pool.py
tensorpack/models/pool.py
+58
-1
No files found.
scripts/dump_train_config.py
View file @
ac6e140f
...
...
@@ -11,6 +11,7 @@ import tqdm
import
os
from
tensorpack.utils
import
logger
from
tensorpack.utils.fs
import
mkdir_p
from
tensorpack.dataflow
import
*
parser
=
argparse
.
ArgumentParser
()
...
...
@@ -44,13 +45,13 @@ if args.output:
NR_DP_TEST
=
args
.
number
logger
.
info
(
"Testing dataflow speed:"
)
ds
=
RepeatedData
(
config
.
dataset
,
-
1
)
with
tqdm
.
tqdm
(
total
=
NR_DP_TEST
,
leave
=
True
,
unit
=
'data points'
)
as
pbar
:
for
idx
,
dp
in
enumerate
(
config
.
dataset
.
get_data
()):
for
idx
,
dp
in
enumerate
(
ds
.
get_data
()):
del
dp
if
idx
>
NR_DP_TEST
:
break
pbar
.
update
()
from
IPython
import
embed
;
embed
()
tensorpack/dataflow/common.py
View file @
ac6e140f
...
...
@@ -10,8 +10,8 @@ from .base import DataFlow, ProxyDataFlow
from
..utils
import
*
__all__
=
[
'BatchData'
,
'FixedSizeData'
,
'FakeData'
,
'MapData'
,
'
MapDataComponent'
,
'RandomChooseData'
,
'RandomMix
Data'
,
'JoinData'
,
'ConcatData'
,
'SelectComponent'
]
'
RepeatedData'
,
'MapDataComponent'
,
'RandomChoose
Data'
,
'
RandomMixData'
,
'
JoinData'
,
'ConcatData'
,
'SelectComponent'
]
class
BatchData
(
ProxyDataFlow
):
def
__init__
(
self
,
ds
,
batch_size
,
remainder
=
False
):
...
...
tensorpack/dataflow/dataset/bsds500.py
View file @
ac6e140f
...
...
@@ -24,7 +24,7 @@ class BSDS500(DataFlow):
Produce (image, label) pair, where image has shape (321, 481, 3) and
ranges in [0,255]. Label is binary and has shape (321, 481).
Those pixels annotated as boundaries by >= 3
out of 5
annotators are
Those pixels annotated as boundaries by >= 3 annotators are
considered positive examples. This is used in `Holistically-Nested Edge Detection
<http://arxiv.org/abs/1504.06375>`_.
"""
...
...
@@ -71,7 +71,8 @@ class BSDS500(DataFlow):
imgid
=
os
.
path
.
basename
(
f
)
.
split
(
'.'
)[
0
]
gt_file
=
os
.
path
.
join
(
gt_dir
,
imgid
)
gt
=
loadmat
(
gt_file
)[
'groundTruth'
][
0
]
gt
=
sum
(
gt
[
k
][
'Boundaries'
][
0
][
0
]
for
k
in
range
(
5
))
n_annot
=
gt
.
shape
[
0
]
gt
=
sum
(
gt
[
k
][
'Boundaries'
][
0
][
0
]
for
k
in
range
(
n_annot
))
gt
[
gt
<
3
]
=
0
gt
[
gt
!=
0
]
=
1
if
gt
.
shape
[
0
]
>
gt
.
shape
[
1
]:
...
...
tensorpack/dataflow/format.py
View file @
ac6e140f
...
...
@@ -11,7 +11,7 @@ from six.moves import range
try
:
import
h5py
except
ImportError
:
logger
.
error
(
"Error in 'import h5py'. HDF5Data won't be available."
)
logger
.
warn
(
"Error in 'import h5py'. HDF5Data won't be available."
)
__all__
=
[]
else
:
__all__
=
[
'HDF5Data'
]
...
...
tensorpack/dataflow/imgaug/base.py
View file @
ac6e140f
...
...
@@ -4,6 +4,7 @@
from
abc
import
abstractmethod
,
ABCMeta
from
...utils
import
get_rng
from
six.moves
import
zip
__all__
=
[
'ImageAugmentor'
,
'AugmentorList'
]
...
...
tensorpack/dataflow/prefetch.py
View file @
ac6e140f
...
...
@@ -17,7 +17,7 @@ from ..utils import logger
try
:
import
zmq
except
ImportError
:
logger
.
error
(
"Error in 'import zmq'. PrefetchDataZMQ won't be available."
)
logger
.
warn
(
"Error in 'import zmq'. PrefetchDataZMQ won't be available."
)
__all__
=
[
'PrefetchData'
]
else
:
__all__
=
[
'PrefetchData'
,
'PrefetchDataZMQ'
]
...
...
tensorpack/models/pool.py
View file @
ac6e140f
...
...
@@ -69,7 +69,7 @@ def FixedUnPooling(x, shape, unpool_mat=None):
:param input: NHWC tensor
:param shape: int or [h, w]
:param unpool_mat: a tf matrix with size=shape. If None, will use a mat
:param unpool_mat: a tf
/np
matrix with size=shape. If None, will use a mat
with 1 at top-left corner.
:returns: NHWC tensor
"""
...
...
@@ -80,6 +80,8 @@ def FixedUnPooling(x, shape, unpool_mat=None):
mat
=
np
.
zeros
(
shape
,
dtype
=
'float32'
)
mat
[
0
][
0
]
=
1
unpool_mat
=
tf
.
Variable
(
mat
,
trainable
=
False
,
name
=
'unpool_mat'
)
elif
isinstance
(
unpool_mat
,
np
.
ndarray
):
unpool_mat
=
tf
.
Variable
(
unpool_mat
,
trainable
=
False
,
name
=
'unpool_mat'
)
assert
unpool_mat
.
get_shape
()
.
as_list
()
==
list
(
shape
)
# perform a tensor-matrix kronecker product
...
...
@@ -96,6 +98,41 @@ def FixedUnPooling(x, shape, unpool_mat=None):
input_shape
[
3
]])
return
prod
@
layer_register
()
def
BilinearUpSample
(
x
,
shape
):
"""
Bilinear upsample the input images.
:param x: input NHWC tensor
:param shape: an integer
"""
def
bilinear_conv_filler
(
s
):
"""
s: width, height of the conv filter
See https://github.com/BVLC/caffe/blob/master/include
%2
Fcaffe
%2
Ffiller.hpp#L244
"""
f
=
np
.
ceil
(
float
(
s
)
/
2
)
c
=
float
(
2
*
f
-
1
-
f
%
2
)
/
(
2
*
f
)
ret
=
np
.
zeros
((
s
,
s
),
dtype
=
'float32'
)
for
x
in
range
(
s
):
for
y
in
range
(
s
):
ret
[
x
,
y
]
=
(
1
-
abs
(
x
/
f
-
c
))
*
(
1
-
abs
(
y
/
f
-
c
))
return
ret
ch
=
x
.
get_shape
()
.
as_list
()[
3
]
shape
=
int
(
shape
)
filter_shape
=
2
*
shape
w
=
bilinear_conv_filler
(
filter_shape
)
w
=
np
.
repeat
(
w
,
ch
*
ch
)
.
reshape
((
filter_shape
,
filter_shape
,
ch
,
ch
))
weight_var
=
tf
.
constant
(
w
,
tf
.
float32
,
shape
=
(
filter_shape
,
filter_shape
,
ch
,
ch
))
unpool_mat
=
np
.
zeros
((
shape
,
shape
),
dtype
=
'float32'
)
unpool_mat
[
-
1
,
-
1
]
=
1
x
=
FixedUnPooling
(
'unpool'
,
x
,
shape
,
unpool_mat
)
output
=
tf
.
nn
.
conv2d
(
x
,
weight_var
,
[
1
,
1
,
1
,
1
],
padding
=
'SAME'
)
return
output
from
._test
import
TestModel
class
TestPool
(
TestModel
):
def
test_fixed_unpooling
(
self
):
...
...
@@ -113,3 +150,23 @@ class TestPool(TestModel):
# the rest are zeros
res
[
0
,::
2
,::
2
,
0
]
=
0
self
.
assertTrue
((
res
==
0
)
.
all
())
def
test_upsample
(
self
):
h
,
w
=
5
,
5
scale
=
2
mat
=
np
.
random
.
rand
(
h
,
w
)
.
astype
(
'float32'
)
inp
=
self
.
make_variable
(
mat
)
inp
=
tf
.
reshape
(
inp
,
[
1
,
h
,
w
,
1
])
output
=
BilinearUpSample
(
'upsample'
,
inp
,
scale
)
res
=
self
.
run_variable
(
output
)
from
skimage.transform
import
rescale
res2
=
rescale
(
mat
,
scale
)
diff
=
np
.
abs
(
res2
-
res
[
0
,:,:,
0
])
# not equivalent at corner
diff
[
0
,
0
]
=
diff
[
-
1
,
-
1
]
=
0
self
.
assertTrue
(
diff
.
max
()
<
1e-4
)
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