Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
old_macaon
Commits
1799b40a
Commit
1799b40a
authored
7 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
We now save only best epochs in training
parent
d8964edd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
trainer/include/Trainer.hpp
+12
-9
12 additions, 9 deletions
trainer/include/Trainer.hpp
trainer/src/Trainer.cpp
+41
-8
41 additions, 8 deletions
trainer/src/Trainer.cpp
with
53 additions
and
17 deletions
trainer/include/Trainer.hpp
+
12
−
9
View file @
1799b40a
...
@@ -35,6 +35,9 @@ void processAllExamples(
...
@@ -35,6 +35,9 @@ void processAllExamples(
void
printIterationScores
(
FILE
*
output
,
void
printIterationScores
(
FILE
*
output
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesTrain
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesTrain
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesDev
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesDev
,
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
&
trainScores
,
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
&
devScores
,
std
::
map
<
std
::
string
,
int
>
&
bestIter
,
int
nbIter
,
int
curIter
);
int
nbIter
,
int
curIter
);
void
shuffleAllExamples
(
std
::
map
<
Classifier
*
,
MLP
::
Examples
>
&
);
void
shuffleAllExamples
(
std
::
map
<
Classifier
*
,
MLP
::
Examples
>
&
);
...
...
This diff is collapsed.
Click to expand it.
trainer/src/Trainer.cpp
+
41
−
8
View file @
1799b40a
...
@@ -68,6 +68,9 @@ void Trainer::processAllExamples(
...
@@ -68,6 +68,9 @@ void Trainer::processAllExamples(
void
Trainer
::
printIterationScores
(
FILE
*
output
,
void
Trainer
::
printIterationScores
(
FILE
*
output
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesTrain
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesTrain
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesDev
,
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
&
nbExamplesDev
,
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
&
trainScores
,
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
&
devScores
,
std
::
map
<
std
::
string
,
int
>
&
bestIter
,
int
nbIter
,
int
curIter
)
int
nbIter
,
int
curIter
)
{
{
fprintf
(
output
,
"Iteration %d/%d :
\n
"
,
curIter
+
1
,
nbIter
);
fprintf
(
output
,
"Iteration %d/%d :
\n
"
,
curIter
+
1
,
nbIter
);
...
@@ -75,10 +78,34 @@ void Trainer::printIterationScores(FILE * output,
...
@@ -75,10 +78,34 @@ void Trainer::printIterationScores(FILE * output,
{
{
float
scoreTrain
=
100.0
*
it
.
second
.
second
/
it
.
second
.
first
;
float
scoreTrain
=
100.0
*
it
.
second
.
second
/
it
.
second
.
first
;
float
scoreDev
=
devConfig
?
100.0
*
nbExamplesDev
[
it
.
first
].
second
/
nbExamplesDev
[
it
.
first
].
first
:
-
1.0
;
float
scoreDev
=
devConfig
?
100.0
*
nbExamplesDev
[
it
.
first
].
second
/
nbExamplesDev
[
it
.
first
].
first
:
-
1.0
;
trainScores
[
it
.
first
].
emplace_back
(
scoreTrain
);
devScores
[
it
.
first
].
emplace_back
(
scoreDev
);
bool
isBest
=
curIter
?
false
:
true
;
if
(
devConfig
)
if
(
devConfig
)
fprintf
(
output
,
"
\t
%s accuracy : train(%.2f%%) dev(%.2f%%)
\n
"
,
it
.
first
.
c_str
(),
scoreTrain
,
scoreDev
);
{
if
(
scoreDev
>
devScores
[
it
.
first
][
bestIter
[
it
.
first
]])
{
isBest
=
true
;
bestIter
[
it
.
first
]
=
devScores
[
it
.
first
].
size
()
-
1
;
}
}
else
else
fprintf
(
output
,
"
\t
%s accuracy : train(%.2f%%)
\n
"
,
it
.
first
.
c_str
(),
scoreTrain
);
{
if
(
scoreTrain
>
trainScores
[
it
.
first
][
bestIter
[
it
.
first
]])
{
isBest
=
true
;
bestIter
[
it
.
first
]
=
trainScores
[
it
.
first
].
size
()
-
1
;
}
}
if
(
devConfig
)
fprintf
(
output
,
"
\t
%s accuracy : train(%.2f%%) dev(%.2f%%)"
,
it
.
first
.
c_str
(),
scoreTrain
,
scoreDev
);
else
fprintf
(
output
,
"
\t
%s accuracy : train(%.2f%%)"
,
it
.
first
.
c_str
(),
scoreTrain
);
fprintf
(
output
,
"%s"
,
isBest
?
" SAVED
\n
"
:
"
\n
"
);
}
}
}
}
...
@@ -100,6 +127,10 @@ void Trainer::trainBatched(int nbIter, int batchSize, bool mustShuffle)
...
@@ -100,6 +127,10 @@ void Trainer::trainBatched(int nbIter, int batchSize, bool mustShuffle)
if
(
devMcd
&&
devConfig
)
if
(
devMcd
&&
devConfig
)
getExamplesByClassifier
(
devExamples
,
*
devConfig
);
getExamplesByClassifier
(
devExamples
,
*
devConfig
);
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
trainScores
;
std
::
map
<
std
::
string
,
std
::
vector
<
float
>
>
devScores
;
std
::
map
<
std
::
string
,
int
>
bestIter
;
for
(
int
i
=
0
;
i
<
nbIter
;
i
++
)
for
(
int
i
=
0
;
i
<
nbIter
;
i
++
)
{
{
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
nbExamplesTrain
;
std
::
map
<
std
::
string
,
std
::
pair
<
int
,
int
>
>
nbExamplesTrain
;
...
@@ -120,14 +151,16 @@ void Trainer::trainBatched(int nbIter, int batchSize, bool mustShuffle)
...
@@ -120,14 +151,16 @@ void Trainer::trainBatched(int nbIter, int batchSize, bool mustShuffle)
return
c
->
getScoreOnBatch
(
ex
,
s
,
e
);
return
c
->
getScoreOnBatch
(
ex
,
s
,
e
);
});
});
printIterationScores
(
stderr
,
nbExamplesTrain
,
nbExamplesDev
,
nbIter
,
i
);
printIterationScores
(
stderr
,
nbExamplesTrain
,
nbExamplesDev
,
}
trainScores
,
devScores
,
bestIter
,
nbIter
,
i
);
auto
&
classifiers
=
tm
.
getClassifiers
();
auto
&
classifiers
=
tm
.
getClassifiers
();
for
(
Classifier
*
cla
:
classifiers
)
for
(
Classifier
*
cla
:
classifiers
)
if
(
cla
->
needsTrain
())
if
(
cla
->
needsTrain
())
if
(
bestIter
[
cla
->
name
]
==
i
)
cla
->
save
();
cla
->
save
();
}
}
}
void
Trainer
::
train
(
int
nbIter
,
int
batchSize
,
bool
mustShuffle
)
void
Trainer
::
train
(
int
nbIter
,
int
batchSize
,
bool
mustShuffle
)
{
{
...
...
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