Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
cac8f31e
"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "da8e2a04479f96ad9c57eaf25ed26b79b239b05c"
Commit
cac8f31e
authored
Nov 19, 2016
by
Davis King
Browse files
merged
parents
d7e4b88d
52627635
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
dlib/dnn/trainer.h
dlib/dnn/trainer.h
+30
-7
No files found.
dlib/dnn/trainer.h
View file @
cac8f31e
...
@@ -743,6 +743,9 @@ namespace dlib
...
@@ -743,6 +743,9 @@ namespace dlib
main_iteration_counter
=
0
;
main_iteration_counter
=
0
;
main_iteration_counter_at_last_disk_sync
=
0
;
main_iteration_counter_at_last_disk_sync
=
0
;
prob_loss_increasing_thresh_default_value
=
0.99
;
prob_loss_increasing_thresh_max_value
=
0.99999
;
prob_loss_increasing_thresh
=
prob_loss_increasing_thresh_default_value
;
start
();
start
();
}
}
...
@@ -853,8 +856,6 @@ namespace dlib
...
@@ -853,8 +856,6 @@ namespace dlib
// previously saved state in the hopes that the problem won't reoccur.
// previously saved state in the hopes that the problem won't reoccur.
if
(
loss_increased_since_last_disk_sync
())
if
(
loss_increased_since_last_disk_sync
())
{
{
// reload from the previous sync file. The file should exist since we
// checked that main_iteration_counter_at_last_disk_sync != 0.
std
::
ifstream
fin
(
sync_filename
,
std
::
ios
::
binary
);
std
::
ifstream
fin
(
sync_filename
,
std
::
ios
::
binary
);
deserialize
(
*
this
,
fin
);
deserialize
(
*
this
,
fin
);
if
(
verbose
)
if
(
verbose
)
...
@@ -881,12 +882,12 @@ namespace dlib
...
@@ -881,12 +882,12 @@ namespace dlib
}
}
}
}
bool
loss_increased_since_last_disk_sync
()
const
bool
loss_increased_since_last_disk_sync
()
{
{
size_t
gradient_updates_since_last_sync
=
main_iteration_counter
-
main_iteration_counter_at_last_disk_sync
;
size_t
gradient_updates_since_last_sync
=
main_iteration_counter
-
main_iteration_counter_at_last_disk_sync
;
// if we haven't synced anything to disk yet then return false.
// if we haven't synced anything to disk yet then return false.
if
(
main_iteration_counter_at_last_disk_sync
==
0
)
if
(
!
std
::
ifstream
(
sync_filename
,
std
::
ios
::
binary
)
)
return
false
;
return
false
;
for
(
auto
x
:
previous_loss_values
)
for
(
auto
x
:
previous_loss_values
)
...
@@ -897,7 +898,8 @@ namespace dlib
...
@@ -897,7 +898,8 @@ namespace dlib
return
true
;
return
true
;
}
}
// if we haven't seen much data yet then just say false.
// if we haven't seen much data yet then just say false. Or, alternatively, if
// it's been too long since the last sync then don't reload either.
if
(
gradient_updates_since_last_sync
<
30
||
previous_loss_values
.
size
()
<
2
*
gradient_updates_since_last_sync
)
if
(
gradient_updates_since_last_sync
<
30
||
previous_loss_values
.
size
()
<
2
*
gradient_updates_since_last_sync
)
return
false
;
return
false
;
...
@@ -908,7 +910,25 @@ namespace dlib
...
@@ -908,7 +910,25 @@ namespace dlib
g
.
add
(
previous_loss_values
[
i
]);
g
.
add
(
previous_loss_values
[
i
]);
// if the loss is very likely to be increasing then return true
// if the loss is very likely to be increasing then return true
return
g
.
probability_gradient_greater_than
(
0
)
>
0.99
;
const
double
prob
=
g
.
probability_gradient_greater_than
(
0
);
if
(
prob
>
prob_loss_increasing_thresh
&&
prob_loss_increasing_thresh
<=
prob_loss_increasing_thresh_max_value
)
{
// Exponentially decay the threshold towards 1 so that if we keep finding
// the loss to be increasing over and over we will make the test
// progressively harder and harder until it fails, therefore ensuring we
// can't get stuck reloading from a previous state over and over.
prob_loss_increasing_thresh
=
0.1
*
prob_loss_increasing_thresh
+
0.9
*
1
;
return
true
;
}
else
{
// decay back to the default threshold
prob_loss_increasing_thresh
=
std
::
pow
(
prob_loss_increasing_thresh
,
10.0
);
// but don't decay below the default value
prob_loss_increasing_thresh
=
std
::
max
(
prob_loss_increasing_thresh
,
prob_loss_increasing_thresh_default_value
);
return
false
;
}
}
}
...
@@ -1043,9 +1063,12 @@ namespace dlib
...
@@ -1043,9 +1063,12 @@ namespace dlib
std
::
rethrow_exception
(
eptr
);
std
::
rethrow_exception
(
eptr
);
}
}
// These
two
variables are not serialized
// These
5
variables are not serialized
size_t
main_iteration_counter
;
size_t
main_iteration_counter
;
size_t
main_iteration_counter_at_last_disk_sync
;
size_t
main_iteration_counter_at_last_disk_sync
;
double
prob_loss_increasing_thresh_default_value
;
double
prob_loss_increasing_thresh_max_value
;
double
prob_loss_increasing_thresh
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment