Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
acb0ea4e
Commit
acb0ea4e
authored
Aug 24, 2018
by
Toby Boyd
Committed by
Taylor Robie
Aug 24, 2018
Browse files
Add top_5 to to eval to resnet (#5178)
* Add top_5 to to eval. * labels shape to [?] from [?,1] matches unittest.
parent
7f895ce5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
official/resnet/imagenet_main.py
official/resnet/imagenet_main.py
+1
-1
official/resnet/resnet_run_loop.py
official/resnet/resnet_run_loop.py
+15
-8
No files found.
official/resnet/imagenet_main.py
View file @
acb0ea4e
...
...
@@ -97,7 +97,7 @@ def _parse_example_proto(example_serialized):
feature_map
=
{
'image/encoded'
:
tf
.
FixedLenFeature
([],
dtype
=
tf
.
string
,
default_value
=
''
),
'image/class/label'
:
tf
.
FixedLenFeature
([
1
],
dtype
=
tf
.
int64
,
'image/class/label'
:
tf
.
FixedLenFeature
([],
dtype
=
tf
.
int64
,
default_value
=-
1
),
'image/class/text'
:
tf
.
FixedLenFeature
([],
dtype
=
tf
.
string
,
default_value
=
''
),
...
...
official/resnet/resnet_run_loop.py
View file @
acb0ea4e
...
...
@@ -284,14 +284,15 @@ def resnet_model_fn(features, labels, mode, model_class,
)
def
_dense_grad_filter
(
gvs
):
'''
only apply gradient updates to the final layer. This function is used for
fine tuning
"""Only apply gradient updates to the final layer.
This function is used for fine tuning.
Args:
gvs
: list of tuples with gradients and variable info
gvs: list of tuples with gradients and variable info
Returns:
filtered gradients so that only the dense layer remains
'''
"""
return
[(
g
,
v
)
for
g
,
v
in
gvs
if
'dense'
in
v
.
name
]
if
loss_scale
!=
1
:
...
...
@@ -320,12 +321,18 @@ def resnet_model_fn(features, labels, mode, model_class,
train_op
=
None
accuracy
=
tf
.
metrics
.
accuracy
(
labels
,
predictions
[
'classes'
])
metrics
=
{
'accuracy'
:
accuracy
}
accuracy_top_5
=
tf
.
metrics
.
mean
(
tf
.
nn
.
in_top_k
(
predictions
=
logits
,
targets
=
labels
,
k
=
5
,
name
=
'top_5_op'
))
metrics
=
{
'accuracy'
:
accuracy
,
'accuracy_top_5'
:
accuracy_top_5
}
# Create a tensor named train_accuracy for logging purposes
tf
.
identity
(
accuracy
[
1
],
name
=
'train_accuracy'
)
tf
.
identity
(
accuracy_top_5
[
1
],
name
=
'train_accuracy_top_5'
)
tf
.
summary
.
scalar
(
'train_accuracy'
,
accuracy
[
1
])
tf
.
summary
.
scalar
(
'train_accuracy_top_5'
,
accuracy_top_5
[
1
])
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
...
...
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