Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
5ba976b8
Commit
5ba976b8
authored
6 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests on moving average
parent
bd586c1c
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!68
Several changes
Pipeline
#24651
failed
6 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/test/test_estimator_onegraph.py
+13
-18
13 additions, 18 deletions
bob/learn/tensorflow/test/test_estimator_onegraph.py
bob/learn/tensorflow/test/test_image_dataset.py
+4
-7
4 additions, 7 deletions
bob/learn/tensorflow/test/test_image_dataset.py
with
17 additions
and
25 deletions
bob/learn/tensorflow/test/test_estimator_onegraph.py
+
13
−
18
View file @
5ba976b8
...
...
@@ -221,15 +221,8 @@ def test_moving_average_trainer():
# define a fixed input data
# train the same network with the same initialization
# evaluate it
# did it change? no -> good
# train it again with moving average
# Is it different from no moving average? yes -> good
no_moving_average
=
{
'
accuracy
'
:
0.128
,
'
loss
'
:
5.3208413
,
'
global_step
'
:
188
}
with_moving_average
=
{
'
accuracy
'
:
0.14
,
'
loss
'
:
2.3772557
,
'
global_step
'
:
188
}
resume_moving_average
=
{
'
accuracy
'
:
0.172
,
'
loss
'
:
2.2985911
,
'
global_step
'
:
376
}
# train and evaluate it again with moving average
# Accuracy should be lower when moving average is on
try
:
# Creating tf records for mnist
...
...
@@ -258,8 +251,7 @@ def test_moving_average_trainer():
validation_batch_size
,
epochs
=
1
)
from
bob.learn.tensorflow.network.SimpleCNN
import
(
new_architecture
as
architecture
)
from
bob.learn.tensorflow.network.Dummy
import
dummy
as
architecture
run_config
=
reproducible
.
set_seed
(
183
,
183
)[
1
]
run_config
=
run_config
.
replace
(
save_checkpoints_steps
=
2000
)
...
...
@@ -275,29 +267,32 @@ def test_moving_average_trainer():
apply_moving_averages
=
apply_moving_averages
,
)
def
_evaluate
(
estimator
,
oracle
,
delete
=
True
):
def
_evaluate
(
estimator
,
delete
=
True
):
try
:
estimator
.
train
(
input_fn
)
evaluations
=
estimator
.
evaluate
(
input_fn_validation
)
finally
:
if
delete
:
shutil
.
rmtree
(
estimator
.
model_dir
,
ignore_errors
=
True
)
for
k
in
(
'
accuracy
'
,
'
loss
'
,
'
global_step
'
):
assert
numpy
.
allclose
(
evaluations
[
k
],
oracle
[
k
]),
\
(
k
,
evaluations
,
oracle
)
return
evaluations
estimator
=
_estimator
(
False
)
_evaluate
(
estimator
,
no_moving_average
,
delete
=
True
)
evaluations
=
_evaluate
(
estimator
,
delete
=
True
)
no_moving_average_acc
=
evaluations
[
'
accuracy
'
]
# same as above with moving average
estimator
=
_estimator
(
True
)
_evaluate
(
estimator
,
with_moving_average
,
delete
=
False
)
evaluations
=
_evaluate
(
estimator
,
delete
=
False
)
with_moving_average_acc
=
evaluations
[
'
accuracy
'
]
assert
no_moving_average_acc
>
with_moving_average_acc
,
\
(
no_moving_average_acc
,
with_moving_average_acc
)
# Can it resume training?
del
estimator
tf
.
reset_default_graph
()
estimator
=
_estimator
(
True
)
_evaluate
(
estimator
,
resume_moving_average
,
delete
=
True
)
_evaluate
(
estimator
,
delete
=
True
)
finally
:
try
:
...
...
This diff is collapsed.
Click to expand it.
bob/learn/tensorflow/test/test_image_dataset.py
+
4
−
7
View file @
5ba976b8
...
...
@@ -38,7 +38,8 @@ def test_logitstrainer_images():
n_classes
=
10
,
loss_op
=
mean_cross_entropy_loss
,
embedding_validation
=
embedding_validation
,
validation_batch_size
=
validation_batch_size
)
validation_batch_size
=
validation_batch_size
,
apply_moving_averages
=
False
)
run_logitstrainer_images
(
trainer
)
finally
:
try
:
...
...
@@ -94,12 +95,8 @@ def run_logitstrainer_images(trainer):
trainer
.
train
(
input_fn
,
steps
=
steps
,
hooks
=
hooks
)
if
not
trainer
.
embedding_validation
:
acc
=
trainer
.
evaluate
(
input_fn_validation
)
assert
acc
[
'
accuracy
'
]
>
0.30
else
:
acc
=
trainer
.
evaluate
(
input_fn_validation
)
assert
acc
[
'
accuracy
'
]
>
0.30
acc
=
trainer
.
evaluate
(
input_fn_validation
)
assert
acc
[
'
accuracy
'
]
>
0.30
,
acc
[
'
accuracy
'
]
# Cleaning up
tf
.
reset_default_graph
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment