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
83c3a098
Commit
83c3a098
authored
Jul 27, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name scope clean-ups in regularization and resnet (#340)
parent
979d18ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
23 deletions
+26
-23
examples/ResNet/imagenet_resnet_utils.py
examples/ResNet/imagenet_resnet_utils.py
+17
-15
tensorpack/models/regularize.py
tensorpack/models/regularize.py
+9
-8
No files found.
examples/ResNet/imagenet_resnet_utils.py
View file @
83c3a098
...
...
@@ -157,19 +157,20 @@ def eval_on_ILSVRC12(model, model_file, dataflow):
def
image_preprocess
(
image
,
bgr
=
True
):
if
image
.
dtype
.
base_dtype
!=
tf
.
float32
:
image
=
tf
.
cast
(
image
,
tf
.
float32
)
image
=
image
*
(
1.0
/
255
)
mean
=
[
0.485
,
0.456
,
0.406
]
# rgb
std
=
[
0.229
,
0.224
,
0.225
]
if
bgr
:
mean
=
mean
[::
-
1
]
std
=
std
[::
-
1
]
image_mean
=
tf
.
constant
(
mean
,
dtype
=
tf
.
float32
)
image_std
=
tf
.
constant
(
std
,
dtype
=
tf
.
float32
)
image
=
(
image
-
image_mean
)
/
image_std
return
image
with
tf
.
name_scope
(
'image_preprocess'
):
if
image
.
dtype
.
base_dtype
!=
tf
.
float32
:
image
=
tf
.
cast
(
image
,
tf
.
float32
)
image
=
image
*
(
1.0
/
255
)
mean
=
[
0.485
,
0.456
,
0.406
]
# rgb
std
=
[
0.229
,
0.224
,
0.225
]
if
bgr
:
mean
=
mean
[::
-
1
]
std
=
std
[::
-
1
]
image_mean
=
tf
.
constant
(
mean
,
dtype
=
tf
.
float32
)
image_std
=
tf
.
constant
(
std
,
dtype
=
tf
.
float32
)
image
=
(
image
-
image_mean
)
/
image_std
return
image
def
compute_loss_and_error
(
logits
,
label
):
...
...
@@ -177,8 +178,9 @@ def compute_loss_and_error(logits, label):
loss
=
tf
.
reduce_mean
(
loss
,
name
=
'xentropy-loss'
)
def
prediction_incorrect
(
logits
,
label
,
topk
=
1
,
name
=
'incorrect_vector'
):
return
tf
.
cast
(
tf
.
logical_not
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
topk
)),
tf
.
float32
,
name
=
name
)
with
tf
.
name_scope
(
'prediction_incorrect'
):
x
=
tf
.
logical_not
(
tf
.
nn
.
in_top_k
(
logits
,
label
,
topk
))
return
tf
.
cast
(
x
,
tf
.
float32
,
name
=
name
)
wrong
=
prediction_incorrect
(
logits
,
label
,
1
,
name
=
'wrong-top1'
)
add_moving_summary
(
tf
.
reduce_mean
(
wrong
,
name
=
'train-error-top1'
))
...
...
tensorpack/models/regularize.py
View file @
83c3a098
...
...
@@ -46,14 +46,15 @@ def regularize_cost(regex, func, name='regularize_cost'):
# If vars are replicated, only regularize those in the current tower
params
=
ctx
.
filter_vars_by_vs_name
(
params
)
costs
=
[]
for
p
in
params
:
para_name
=
p
.
name
if
re
.
search
(
regex
,
para_name
):
costs
.
append
(
func
(
p
))
_log_regularizer
(
para_name
)
if
not
costs
:
return
tf
.
constant
(
0
,
dtype
=
tf
.
float32
,
name
=
'empty_'
+
name
)
with
tf
.
name_scope
(
'regularize_cost'
):
costs
=
[]
for
p
in
params
:
para_name
=
p
.
name
if
re
.
search
(
regex
,
para_name
):
costs
.
append
(
func
(
p
))
_log_regularizer
(
para_name
)
if
not
costs
:
return
tf
.
constant
(
0
,
dtype
=
tf
.
float32
,
name
=
'empty_'
+
name
)
return
tf
.
add_n
(
costs
,
name
=
name
)
...
...
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