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
7622fe10
Commit
7622fe10
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
experiment setup class, improved time tracking
parent
a06f6d09
No related branches found
No related tags found
2 merge requests
!12
Experiment Setup finished
,
!11
finish run script creation, /close #11
Pipeline
#25922
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
run.py
+77
-8
77 additions, 8 deletions
run.py
src/helpers.py
+10
-3
10 additions, 3 deletions
src/helpers.py
test/test_helpers.py
+9
-2
9 additions, 2 deletions
test/test_helpers.py
with
96 additions
and
13 deletions
run.py
+
77
−
8
View file @
7622fe10
...
@@ -6,22 +6,91 @@ import logging
...
@@ -6,22 +6,91 @@ import logging
from
src.helpers
import
TimeTracking
from
src.helpers
import
TimeTracking
from
src
import
helpers
from
src
import
helpers
import
argparse
import
argparse
import
time
if
__name__
==
"
__main__
"
:
formatter
=
"
%(asctime)s - %(levelname)s: %(message)s [%(filename)s:%(funcName)s:%(lineno)s]
"
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
formatter
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
experiment date
'
,
metavar
=
'
exp_date
'
,
type
=
str
,
nargs
=
1
,
help
=
'
set experiment date as string
'
,
default
=
None
)
logging
.
info
(
"
start run script
"
)
class
run
(
object
):
total_time
=
TimeTracking
()
"""
basic run class to measure execution time. Either call this class calling it by
'
with
'
or delete the class instance
after finishing the measurement. The duration result is logged.
"""
def
__init__
(
self
):
self
.
time
=
TimeTracking
()
logging
.
info
(
f
"
{
self
.
__class__
.
__name__
}
started
"
)
def
__del__
(
self
):
self
.
time
.
stop
()
logging
.
info
(
f
"
{
self
.
__class__
.
__name__
}
finished after
{
self
.
time
}
"
)
def
__enter__
(
self
):
pass
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
pass
def
do_stuff
(
self
):
time
.
sleep
(
2
)
class
ExperimentSetup
:
def
__init__
(
self
):
self
.
data_path
=
None
self
.
experiment_path
=
None
self
.
experiment_name
=
None
self
.
trainable
=
False
self
.
setup_experiment
()
def
setup_experiment
(
self
):
# set data path of this experiment
# set data path of this experiment
data_path
=
helpers
.
prepare_host
()
self
.
data_path
=
helpers
.
prepare_host
()
# set experiment name
# set experiment name
experiment_date
=
parser
.
parse_args
([
"
experiment_date
"
])
experiment_date
=
parser
.
parse_args
([
"
experiment_date
"
])
experiment_name
,
experiment_path
=
helpers
.
set_experiment_name
(
experiment_date
=
experiment_date
)
self
.
experiment_name
,
self
.
experiment_path
=
helpers
.
set_experiment_name
(
experiment_date
=
experiment_date
)
# set if model shall be trained or not
# set if model shall be trained or not
self
.
trainable
=
True
class
PreProcessing
(
run
):
def
__init__
(
self
,
setup
):
super
().
__init__
()
self
.
setup
=
setup
class
Training
(
run
):
def
__init__
(
self
,
setup
):
super
().
__init__
()
self
.
setup
=
setup
class
PostProcessing
(
run
):
def
__init__
(
self
,
setup
):
super
().
__init__
()
self
.
setup
=
setup
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
experiment date
'
,
metavar
=
'
exp_date
'
,
type
=
str
,
nargs
=
1
,
help
=
'
set experiment date as string
'
,
default
=
None
)
with
run
():
exp_setup
=
ExperimentSetup
()
PreProcessing
(
exp_setup
)
Training
(
exp_setup
)
PostProcessing
(
exp_setup
)
This diff is collapsed.
Click to expand it.
src/helpers.py
+
10
−
3
View file @
7622fe10
...
@@ -103,6 +103,7 @@ class TimeTracking(object):
...
@@ -103,6 +103,7 @@ class TimeTracking(object):
def
_start
(
self
):
def
_start
(
self
):
self
.
start
=
time
.
time
()
self
.
start
=
time
.
time
()
self
.
end
=
None
def
_end
(
self
):
def
_end
(
self
):
self
.
end
=
time
.
time
()
self
.
end
=
time
.
time
()
...
@@ -119,9 +120,15 @@ class TimeTracking(object):
...
@@ -119,9 +120,15 @@ class TimeTracking(object):
def
run
(
self
):
def
run
(
self
):
self
.
_start
()
self
.
_start
()
def
stop
(
self
):
def
stop
(
self
,
get_duration
=
False
):
self
.
end
=
time
.
time
()
if
self
.
end
is
None
:
return
self
.
_duration
()
self
.
_end
()
else
:
msg
=
f
"
Time was already stopped
{
time
.
time
()
-
self
.
end
}
s ago.
"
logging
.
error
(
msg
)
raise
AssertionError
(
msg
)
if
get_duration
:
return
self
.
duration
()
def
duration
(
self
):
def
duration
(
self
):
return
self
.
_duration
()
return
self
.
_duration
()
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers.py
+
9
−
2
View file @
7622fe10
...
@@ -127,14 +127,21 @@ class TestTimeTracking:
...
@@ -127,14 +127,21 @@ class TestTimeTracking:
def
test_stop
(
self
):
def
test_stop
(
self
):
t
=
TimeTracking
()
t
=
TimeTracking
()
assert
t
.
end
is
None
assert
t
.
end
is
None
duration
=
t
.
stop
()
duration
=
t
.
stop
(
get_duration
=
True
)
assert
duration
==
t
.
_duration
()
assert
duration
==
t
.
_duration
()
with
pytest
.
raises
(
AssertionError
)
as
e
:
t
.
stop
()
assert
"
Time was already stopped
"
in
e
.
value
.
args
[
0
]
t
.
run
()
assert
t
.
end
is
None
assert
t
.
stop
()
is
None
assert
t
.
end
is
not
None
def
test_duration
(
self
):
def
test_duration
(
self
):
t
=
TimeTracking
()
t
=
TimeTracking
()
duration
=
t
duration
=
t
assert
duration
is
not
None
assert
duration
is
not
None
duration
=
t
.
stop
()
duration
=
t
.
stop
(
get_duration
=
True
)
assert
duration
==
t
.
duration
()
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