Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KI-WaVo
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Landesamt für Umwelt
KI-WaVo
Commits
dc483ebf
Commit
dc483ebf
authored
6 months ago
by
Michel Spils
Browse files
Options
Downloads
Patches
Plain Diff
tiny script to export csv metrics
parent
f4bcf62c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scripts/extract_metrics.py
+54
-0
54 additions, 0 deletions
src/scripts/extract_metrics.py
with
54 additions
and
0 deletions
src/scripts/extract_metrics.py
0 → 100644
+
54
−
0
View file @
dc483ebf
import
argparse
from
ast
import
arg
from
tbparse
import
SummaryReader
import
os
from
pathlib
import
Path
def
extract_summaries_to_csv
(
root_dir
,
metrics
=
None
,
force
=
False
):
"""
Takes a root directory and extracts metrics from the tensorboard file into a metrics.csv file.
Tensorboard files look something like events.out.tfevents.1701686993.kiel.2222904.0
default metrics are
"
hp/test_p10
"
,
"
hp/test_p20
"
,
"
hp/test_rmse
"
,
"
hp/test_p10_flood
"
,
"
hp/test_p20_flood
"
,
"
hp/test_rmse_flood
"
Args:
root_dir (str/path): Directory with folders containing tensorboard files and models. Those are expected to beging with version
metrics (list[str], optional): List of metrics to extract. Defaults to None.
"""
if
metrics
is
None
:
metrics
=
[
"
hp/test_p10
"
,
"
hp/test_p20
"
,
"
hp/test_rmse
"
,
"
hp/test_p10_flood
"
,
"
hp/test_p20_flood
"
,
"
hp/test_rmse_flood
"
]
for
root
,
_
,
files
in
os
.
walk
(
root_dir
):
if
root
.
split
(
"
/
"
)[
-
1
].
startswith
(
"
version
"
):
if
"
metrics.csv
"
in
files
and
not
force
:
print
(
f
"
Skipping
{
root
}
as metrics.csv already exists. Use --force to overwrite
"
)
continue
#log_dir = "../../../data-project/KIWaVo/models/lfu/willenscharen6/lightning_logs/version_0/"
reader_hp
=
SummaryReader
(
root
,
pivot
=
True
)
df
=
reader_hp
.
scalars
df
=
df
.
drop
([
"
step
"
,
"
epoch
"
],
axis
=
1
)[
1
:
49
]
df
=
df
[
metrics
]
df
.
columns
=
df
.
columns
.
str
.
slice
(
3
)
df
.
to_csv
(
root
+
"
/metrics.csv
"
)
print
(
f
"
Extracted metrics for
{
root
}
"
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
"
Extract metrics from tensorboard files to csv. Will check folders that start with
'
version
'"
)
parser
.
add_argument
(
"
root_dir
"
,
type
=
str
,
help
=
"
Root directory with tensorboard files
"
)
parser
.
add_argument
(
"
--metrics
"
,
type
=
str
,
help
=
"""
Metrics to extract.
Default:
"
hp/test_p10
"
,
"
hp/test_p20
"
,
"
hp/test_rmse
"
,
"
hp/test_p10_flood
"
,
"
hp/test_p20_flood
"
,
"
hp/test_rmse_flood
"
It is probably easiert to modify the source code if you want to change the metrics.
"""
,
nargs
=
"
+
"
)
parser
.
add_argument
(
"
--force
"
,
action
=
"
store_true
"
,
help
=
"
Force overwrite of existing metrics.csv files
"
)
args
=
parser
.
parse_args
()
print
(
args
)
extract_summaries_to_csv
(
args
.
root_dir
,
args
.
metrics
,
args
.
force
)
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
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