Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.pytorch
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
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.pytorch
Commits
df5062d4
Commit
df5062d4
authored
7 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Patches
Plain Diff
[trainers] added the functionality to only keep models every N epochs, plus the latest one
parent
853568d1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/pytorch/trainers/DRGANTrainer.py
+18
-2
18 additions, 2 deletions
bob/learn/pytorch/trainers/DRGANTrainer.py
with
18 additions
and
2 deletions
bob/learn/pytorch/trainers/DRGANTrainer.py
+
18
−
2
View file @
df5062d4
...
...
@@ -201,7 +201,7 @@ class DRGANTrainer(object):
return
start_epoch
def
train
(
self
,
dataloader
,
n_epochs
=
10
,
learning_rate
=
0.0002
,
beta1
=
0.5
,
output_dir
=
'
out
'
,
plot
=
False
,
save_sample
=
10
,
pose_random
=
True
):
def
train
(
self
,
dataloader
,
n_epochs
=
10
,
learning_rate
=
0.0002
,
beta1
=
0.5
,
output_dir
=
'
out
'
,
plot
=
False
,
save_sample
=
10
,
pose_random
=
True
,
keep_model
=
1
):
"""
Function that performs the training.
...
...
@@ -230,7 +230,13 @@ class DRGANTrainer(object):
pose_random: boolean
To assign random pose labels to generated images (necessary actually)
keep_model: int
To keep model every X epochs (and the last one)
"""
if
not
pose_random
:
logger
.
warn
(
"
Generating same poses as in training examples
"
)
# create directories
images_dir
=
output_dir
+
"
/images
"
models_dir
=
output_dir
+
"
/models
"
...
...
@@ -271,6 +277,7 @@ class DRGANTrainer(object):
for
epoch
in
range
(
start_epoch
,
n_epochs
):
for
i
,
data
in
enumerate
(
dataloader
,
0
):
start
=
time
.
time
()
# get the batch data, pose and id labels
...
...
@@ -425,7 +432,7 @@ class DRGANTrainer(object):
# save losses
filename
=
log_dir
+
'
/losses_{}_{}.hdf5
'
.
format
(
epoch
,
i
)
f
=
bob
.
io
.
base
.
HDF5File
(
filename
,
'
w
'
)
f
=
bob
.
io
.
base
.
HDF5File
(
filename
,
'
a
'
)
f
.
set
(
'
d_loss
'
,
discriminator_loss
)
f
.
set
(
'
g_loss
'
,
generator_loss
)
del
f
...
...
@@ -461,6 +468,15 @@ class DRGANTrainer(object):
torch
.
save
(
self
.
encoder
.
state_dict
(),
'
%s/encoder_epoch_%d.pth
'
%
(
models_dir
,
epoch
))
torch
.
save
(
self
.
decoder
.
state_dict
(),
'
%s/decoder_epoch_%d.pth
'
%
(
models_dir
,
epoch
))
torch
.
save
(
self
.
discriminator
.
state_dict
(),
'
%s/discriminator_epoch_%d.pth
'
%
(
models_dir
,
epoch
))
# remove models that we don't want to keep
import
glob
,
os
model_files
=
glob
.
glob
(
models_dir
+
'
/*.pth
'
)
for
model_file
in
model_files
:
model_epoch
=
int
(
model_file
.
split
(
'
_
'
)[
-
1
].
split
(
'
.
'
)[
0
])
if
((
model_epoch
%
keep_model
)
!=
0
)
and
(
model_epoch
!=
epoch
):
os
.
remove
(
model_file
)
logger
.
info
(
"
{} removed !
"
.
format
(
model_file
))
def
check_batch_statistics
(
self
,
output_real
,
output_fake
,
output_generator
,
...
...
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