Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OSLO 360-degree image compression
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
On-the-Sphere Learning for Omnidirectional images (OSLO)
OSLO 360-degree image compression
Commits
826f7f1a
Commit
826f7f1a
authored
1 year ago
by
PaulWawerek-L
Browse files
Options
Downloads
Patches
Plain Diff
save always best model during validation
parent
1082bae0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
OSLO-IC
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main_sphere_compression.py
+24
-17
24 additions, 17 deletions
main_sphere_compression.py
with
24 additions
and
17 deletions
main_sphere_compression.py
+
24
−
17
View file @
826f7f1a
...
@@ -327,20 +327,25 @@ def save_config(list_dicts, output_folder, filename=None):
...
@@ -327,20 +327,25 @@ def save_config(list_dicts, output_folder, filename=None):
f
.
write
(
f
"
{
key
:
_
<
40
}
:
{
str
(
val
)
}
\n
"
)
# check this for all kinds of formatting
f
.
write
(
f
"
{
key
:
_
<
40
}
:
{
str
(
val
)
}
\n
"
)
# check this for all kinds of formatting
f
.
write
(
"
=
"
*
60
+
"
\n
"
)
f
.
write
(
"
=
"
*
60
+
"
\n
"
)
def
save_checkpoint
(
state_dics
,
is_best
,
output_folder
,
filename
=
None
):
def
save_checkpoint
(
state_dics
,
is_best
,
output_folder
,
filename
=
None
,
only_best_model
=
False
):
os
.
makedirs
(
output_folder
,
exist_ok
=
True
)
os
.
makedirs
(
output_folder
,
exist_ok
=
True
)
if
filename
:
if
not
only_best_model
:
if
filename
.
endswith
(
'
.tar
'
):
filename
=
filename
.
replace
(
'
.tar
'
,
''
)
if
filename
:
if
filename
.
endswith
(
'
.pth
'
):
filename
=
filename
.
replace
(
'
.pth
'
,
''
)
if
filename
.
endswith
(
'
.tar
'
):
filename
=
filename
.
replace
(
'
.tar
'
,
''
)
else
:
if
filename
.
endswith
(
'
.pth
'
):
filename
=
filename
.
replace
(
'
.pth
'
,
''
)
filename
=
f
"
checkpoint_
{
state_dics
[
'
epoch
'
]
+
1
:
03
d
}
"
else
:
output_fileAddr
=
os
.
path
.
join
(
output_folder
,
filename
+
'
.pth.tar
'
)
filename
=
f
"
checkpoint_
{
state_dics
[
'
epoch
'
]
+
1
:
04
d
}
"
torch
.
save
(
state_dics
,
output_fileAddr
)
print
(
f
'
saved checkpoint to
{
output_fileAddr
}
'
)
output_fileAddr
=
os
.
path
.
join
(
output_folder
,
filename
+
'
.pth.tar
'
)
torch
.
save
(
state_dics
,
output_fileAddr
)
print
(
f
'
saved checkpoint to
{
output_fileAddr
}
'
)
if
is_best
:
if
is_best
:
fp_best
=
os
.
path
.
join
(
output_folder
,
'
checkpoint_best_loss.pth.tar
'
)
fp_best
=
os
.
path
.
join
(
output_folder
,
'
checkpoint_best_loss.pth.tar
'
)
if
only_best_model
:
torch
.
save
(
state_dics
,
fp_best
)
else
:
shutil
.
copyfile
(
output_fileAddr
,
fp_best
)
print
(
f
'
saved best model to
{
fp_best
}
'
)
print
(
f
'
saved best model to
{
fp_best
}
'
)
shutil
.
copyfile
(
output_fileAddr
,
fp_best
)
def
get_model_name
(
string_name
):
def
get_model_name
(
string_name
):
for
ch
in
[
"
,
"
,
"
"
,
"
_
"
,
"
-
"
]:
# replace all with space
for
ch
in
[
"
,
"
,
"
"
,
"
_
"
,
"
-
"
]:
# replace all with space
...
@@ -585,9 +590,10 @@ def main():
...
@@ -585,9 +590,10 @@ def main():
if
args
.
loss_file
:
if
args
.
loss_file
:
with
open
(
os
.
path
.
join
(
args
.
out_dir
,
args
.
loss_file
),
'
a
'
)
as
f
:
with
open
(
os
.
path
.
join
(
args
.
out_dir
,
args
.
loss_file
),
'
a
'
)
as
f
:
f
.
write
(
loss_str
+
'
\n
'
)
f
.
write
(
loss_str
+
'
\n
'
)
perform_validation
=
args
.
validation_data
and
((
epoch
+
1
)
>=
args
.
validation_start
)
if
args
.
validation_data
:
# validation data
if
args
.
validation_data
:
# validation data
if
(
epoch
+
1
)
>=
args
.
validation
_start
:
if
perform_
validation
:
saveVis
=
(((
epoch
+
1
)
%
args
.
interval_save_valtest
==
0
)
or
((
epoch
+
1
)
==
args
.
max_epochs
))
and
(
args
.
foldername_valtest
is
not
None
)
saveVis
=
(((
epoch
+
1
)
%
args
.
interval_save_valtest
==
0
)
or
((
epoch
+
1
)
==
args
.
max_epochs
))
and
(
args
.
foldername_valtest
is
not
None
)
valTestVisFolder
=
os
.
path
.
join
(
args
.
out_dir
,
args
.
foldername_valtest
)
if
saveVis
else
None
valTestVisFolder
=
os
.
path
.
join
(
args
.
out_dir
,
args
.
foldername_valtest
)
if
saveVis
else
None
loss_validation
=
test_epoch
(
validation_dataloader
,
struct_loader
,
net
,
criterion
,
args
.
patch_res_valtest
,
valTestVisFolder
,
args
.
print_freq
,
epoch
)
loss_validation
=
test_epoch
(
validation_dataloader
,
struct_loader
,
net
,
criterion
,
args
.
patch_res_valtest
,
valTestVisFolder
,
args
.
print_freq
,
epoch
)
...
@@ -604,10 +610,11 @@ def main():
...
@@ -604,10 +610,11 @@ def main():
if
not
args
.
no_scheduler
:
if
not
args
.
no_scheduler
:
scheduler
.
step
()
# type: ignore
scheduler
.
step
()
# type: ignore
scheduler_aux
.
step
()
# type: ignore
scheduler_aux
.
step
()
# type: ignore
if
(
epoch
+
1
)
%
args
.
checkpoint_interval
==
0
:
save_regular_checkpoint
=
(
epoch
+
1
)
%
args
.
checkpoint_interval
==
0
is_best
=
loss_validation
[
"
loss
"
]
<
best_loss
if
args
.
validation_data
and
((
epoch
+
1
)
>=
args
.
validation_start
)
else
False
if
save_regular_checkpoint
or
perform_validation
:
best_loss
=
min
(
loss_validation
[
"
loss
"
],
best_loss
)
if
args
.
validation_data
and
((
epoch
+
1
)
>=
args
.
validation_start
)
else
best_loss
is_best
=
loss_validation
[
"
loss
"
]
<
best_loss
if
perform_validation
else
False
best_loss
=
min
(
loss_validation
[
"
loss
"
],
best_loss
)
if
perform_validation
else
best_loss
states
=
{
states
=
{
'
epoch
'
:
epoch
,
'
epoch
'
:
epoch
,
'
net_state_dict
'
:
net
.
state_dict
(),
'
net_state_dict
'
:
net
.
state_dict
(),
...
@@ -619,7 +626,7 @@ def main():
...
@@ -619,7 +626,7 @@ def main():
if
not
args
.
no_scheduler
:
if
not
args
.
no_scheduler
:
states
[
"
scheduler_state_dict
"
]
=
scheduler
.
state_dict
()
states
[
"
scheduler_state_dict
"
]
=
scheduler
.
state_dict
()
states
[
"
scheduler_aux_state_dict
"
]
=
scheduler_aux
.
state_dict
()
states
[
"
scheduler_aux_state_dict
"
]
=
scheduler_aux
.
state_dict
()
save_checkpoint
(
states
,
is_best
,
args
.
out_dir
)
save_checkpoint
(
states
,
is_best
,
args
.
out_dir
,
only_best_model
=
(
not
save_regular_checkpoint
)
)
# Saving last results
# Saving last results
is_best
=
loss_validation
[
"
loss
"
]
<
best_loss
if
args
.
validation_data
else
False
is_best
=
loss_validation
[
"
loss
"
]
<
best_loss
if
args
.
validation_data
else
False
...
...
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