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
73ae9c5a
Commit
73ae9c5a
authored
Aug 19, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add under_nam_socpe decorator
parent
42f2c644
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
5 deletions
+58
-5
examples/ResNet/imagenet_resnet_utils.py
examples/ResNet/imagenet_resnet_utils.py
+3
-2
tensorpack/models/common.py
tensorpack/models/common.py
+11
-2
tensorpack/tfutils/scope_utils.py
tensorpack/tfutils/scope_utils.py
+44
-1
No files found.
examples/ResNet/imagenet_resnet_utils.py
View file @
73ae9c5a
...
@@ -44,7 +44,8 @@ class GoogleNetResize(imgaug.ImageAugmentor):
...
@@ -44,7 +44,8 @@ class GoogleNetResize(imgaug.ImageAugmentor):
out
=
img
[
y1
:
y1
+
hh
,
x1
:
x1
+
ww
]
out
=
img
[
y1
:
y1
+
hh
,
x1
:
x1
+
ww
]
out
=
cv2
.
resize
(
out
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
out
=
cv2
.
resize
(
out
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
return
out
return
out
out
=
cv2
.
resize
(
img
,
(
224
,
224
),
interpolation
=
cv2
.
INTER_CUBIC
)
out
=
imgaug
.
ResizeShortestEdge
(
224
,
interp
=
cv2
.
INTER_CUBIC
)
.
augment
(
img
)
out
=
imgaug
.
CenterCrop
(
224
)
.
augment
(
out
)
return
out
return
out
...
@@ -73,7 +74,7 @@ def fbresnet_augmentor(isTrain):
...
@@ -73,7 +74,7 @@ def fbresnet_augmentor(isTrain):
]
]
else
:
else
:
augmentors
=
[
augmentors
=
[
imgaug
.
ResizeShortestEdge
(
256
),
imgaug
.
ResizeShortestEdge
(
256
,
cv2
.
INTER_CUBIC
),
imgaug
.
CenterCrop
((
224
,
224
)),
imgaug
.
CenterCrop
((
224
,
224
)),
]
]
return
augmentors
return
augmentors
...
...
tensorpack/models/common.py
View file @
73ae9c5a
...
@@ -87,8 +87,6 @@ def layer_register(
...
@@ -87,8 +87,6 @@ def layer_register(
log_shape
=
False
,
log_shape
=
False
,
use_scope
=
True
):
use_scope
=
True
):
"""
"""
Register a layer.
Args:
Args:
log_shape (bool): log input/output shape of this layer
log_shape (bool): log input/output shape of this layer
use_scope (bool or None):
use_scope (bool or None):
...
@@ -97,6 +95,17 @@ def layer_register(
...
@@ -97,6 +95,17 @@ def layer_register(
the scope name argument.
the scope name argument.
It will try to figure out by checking if the first argument
It will try to figure out by checking if the first argument
is string or not.
is string or not.
Returns:
A decorator used to register a layer.
Examples:
.. code-block:: python
@layer_register(use_scope=True)
def add10(x):
return x + tf.get_variable('W', shape=[10])
"""
"""
def
wrapper
(
func
):
def
wrapper
(
func
):
...
...
tensorpack/tfutils/scope_utils.py
View file @
73ae9c5a
...
@@ -14,8 +14,22 @@ __all__ = ['auto_reuse_variable_scope', 'cached_name_scope']
...
@@ -14,8 +14,22 @@ __all__ = ['auto_reuse_variable_scope', 'cached_name_scope']
def
auto_reuse_variable_scope
(
func
):
def
auto_reuse_variable_scope
(
func
):
"""
"""
A decorator which automatically reuse the current variable scope if the
A decorator which automatically reuse
s
the current variable scope if the
function has been called with the same variable scope before.
function has been called with the same variable scope before.
Examples:
.. code-block:: python
@auto_reuse_variable_scope
def myfunc(x):
return tf.layers.conv2d(x, 128, 3)
myfunc(x1) # will inherit parent scope reuse
myfunc(x2) # will reuse
with tf.variable_scope('newscope'):
myfunc(x3) # will inherit parent scope reuse
myfunc(x4) # will reuse
"""
"""
used_scope
=
set
()
used_scope
=
set
()
...
@@ -34,6 +48,35 @@ def auto_reuse_variable_scope(func):
...
@@ -34,6 +48,35 @@ def auto_reuse_variable_scope(func):
return
wrapper
return
wrapper
def
under_name_scope
():
"""
Returns:
A decorator which makes the function happen under a name scope,
which is named by the function itself.
Examples:
.. code-block:: python
@under_name_scope()
def rms(x):
return tf.sqrt( # will be under name scope 'rms'
tf.reduce_mean(tf.square(x)))
Todo:
Add a reuse option.
"""
def
_impl
(
func
):
@
functools
.
wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
name
=
func
.
__name__
with
tf
.
name_scope
(
name
):
return
func
(
*
args
,
**
kwargs
)
return
wrapper
return
_impl
@
graph_memoized
@
graph_memoized
def
_get_cached_ns
(
name
):
def
_get_cached_ns
(
name
):
with
tf
.
name_scope
(
None
):
with
tf
.
name_scope
(
None
):
...
...
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