Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
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
Package 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
03c6aa09
Commit
03c6aa09
authored
2 years ago
by
ogueler@idiap.ch
Browse files
Options
Downloads
Patches
Plain Diff
added function to recognize lowest validation error. Closes
#2
parent
c7068292
No related branches found
No related tags found
1 merge request
!3
Lowest validation loss
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ptbench/engine/trainer.py
+34
-1
34 additions, 1 deletion
src/ptbench/engine/trainer.py
with
34 additions
and
1 deletion
src/ptbench/engine/trainer.py
+
34
−
1
View file @
03c6aa09
...
...
@@ -64,6 +64,37 @@ def check_gpu(device):
gpu_constants
()
),
f
"
Device set to
'
{
device
}
'
, but nvidia-smi is not installed
"
def
initialize_lowest_validation_loss
(
logfile_name
,
arguments
):
"""
Initialize the lowest validation loss from the logfile if it exists and if the training
does not start from epoch 0, which means that a previous training session is resumed.
Parameters
----------
logfile_name : str
The logfile_name which is a join between the output_folder and trainlog.csv
arguments : dict
start and end epochs
"""
if
arguments
[
"
epoch
"
]
!=
0
and
os
.
path
.
exists
(
logfile_name
):
# Open the CSV file
with
open
(
logfile_name
,
'
r
'
)
as
file
:
reader
=
csv
.
DictReader
(
file
)
column_name
=
"
validation_loss
"
if
column_name
not
in
reader
.
fieldnames
:
return
sys
.
float_info
.
max
# Get the values of the desired column as a list
values
=
[
float
(
row
[
column_name
])
for
row
in
reader
]
lowest_value
=
min
(
values
)
logger
.
info
(
f
"
Found lowest validation error from previous session:
{
lowest_value
}
"
)
return
lowest_value
return
sys
.
float_info
.
max
def
save_model_summary
(
output_folder
,
model
):
"""
Save a little summary of the model in a txt file.
...
...
@@ -569,7 +600,9 @@ def run(
# the lowest validation loss obtained so far - this value is updated only
# if a validation set is available
lowest_validation_loss
=
sys
.
float_info
.
max
lowest_validation_loss
=
initialize_lowest_validation_loss
(
logfile_name
,
arguments
)
# set a specific validation criterion if the user has set one
criterion_valid
=
criterion_valid
or
criterion
...
...
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