Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
e936d100
Commit
e936d100
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
implemented time tracking class, /close
#22
parent
2dd1364d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!12
Experiment Setup finished
,
!11
finish run script creation, /close #11
Pipeline
#25847
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers.py
+39
-0
39 additions, 0 deletions
src/helpers.py
test/test_helpers.py
+58
-1
58 additions, 1 deletion
test/test_helpers.py
with
97 additions
and
1 deletion
src/helpers.py
+
39
−
0
View file @
e936d100
...
...
@@ -9,6 +9,7 @@ import math
from
typing
import
Union
import
numpy
as
np
import
os
import
time
def
to_list
(
arg
):
...
...
@@ -84,3 +85,41 @@ class LearningRateDecay(keras.callbacks.History):
self
.
lr
[
'
lr
'
].
append
(
current_lr
)
logging
.
info
(
f
"
Set learning rate to
{
current_lr
}
"
)
return
K
.
get_value
(
self
.
model
.
optimizer
.
lr
)
class
TimeTracking
(
object
):
"""
Track time to measure execution time. Time tracking automatically starts on initialisation and ends by calling stop
method. Duration can always be shown by printing the time tracking object or calling get_current_duration.
"""
def
__init__
(
self
,
start
=
True
):
self
.
start
=
None
self
.
end
=
None
if
start
:
self
.
_start
()
def
_start
(
self
):
self
.
start
=
time
.
time
()
def
_end
(
self
):
self
.
end
=
time
.
time
()
def
_duration
(
self
):
if
self
.
end
:
return
self
.
end
-
self
.
start
else
:
return
time
.
time
()
-
self
.
start
def
__repr__
(
self
):
return
f
"
{
round
(
self
.
_duration
(),
2
)
}
s
"
def
run
(
self
):
self
.
_start
()
def
stop
(
self
):
self
.
end
=
time
.
time
()
return
self
.
_duration
()
def
duration
(
self
):
return
self
.
_duration
()
This diff is collapsed.
Click to expand it.
test/test_helpers.py
+
58
−
1
View file @
e936d100
import
pytest
from
src.helpers
import
to_list
,
check_path_and_create
,
l_p_loss
,
LearningRateDecay
from
src.helpers
import
*
import
logging
import
os
import
keras
...
...
@@ -78,3 +78,60 @@ class TestLearningRateDecay:
model
.
compile
(
optimizer
=
keras
.
optimizers
.
Adam
(),
loss
=
l_p_loss
(
2
))
model
.
fit
(
np
.
array
([
1
,
0
,
2
,
0.5
]),
np
.
array
([
1
,
1
,
0
,
0.5
]),
epochs
=
5
,
callbacks
=
[
lr_decay
])
assert
lr_decay
.
lr
[
'
lr
'
]
==
[
0.02
,
0.02
,
0.02
*
0.95
,
0.02
*
0.95
,
0.02
*
0.95
*
0.95
]
class
TestTimeTracking
:
def
test_init
(
self
):
t
=
TimeTracking
()
assert
t
.
start
is
not
None
assert
t
.
start
<
time
.
time
()
assert
t
.
end
is
None
t2
=
TimeTracking
(
start
=
False
)
assert
t2
.
start
is
None
def
test__start
(
self
):
t
=
TimeTracking
(
start
=
False
)
t
.
_start
()
assert
t
.
start
<
time
.
time
()
def
test__end
(
self
):
t
=
TimeTracking
()
t
.
_end
()
assert
t
.
end
>
t
.
start
def
test__duration
(
self
):
t
=
TimeTracking
()
d1
=
t
.
_duration
()
assert
d1
>
0
d2
=
t
.
_duration
()
assert
d2
>
d1
t
.
_end
()
d3
=
t
.
_duration
()
assert
d3
>
d2
assert
d3
==
t
.
_duration
()
def
test_repr
(
self
):
t
=
TimeTracking
()
t
.
_end
()
duration
=
t
.
_duration
()
assert
t
.
__repr__
().
rstrip
()
==
f
"
{
round
(
duration
,
2
)
}
s
"
.
rstrip
()
def
test_run
(
self
):
t
=
TimeTracking
(
start
=
False
)
assert
t
.
start
is
None
t
.
run
()
assert
t
.
start
is
not
None
def
test_stop
(
self
):
t
=
TimeTracking
()
assert
t
.
end
is
None
duration
=
t
.
stop
()
assert
duration
==
t
.
_duration
()
def
test_duration
(
self
):
t
=
TimeTracking
()
duration
=
t
assert
duration
is
not
None
duration
=
t
.
stop
()
assert
duration
==
t
.
duration
()
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