Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
feb1aa56
Commit
feb1aa56
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
first implementation of lrDecay, loss and lrCallback, no tests yet
parent
430cc664
No related branches found
No related tags found
2 merge requests
!9
new version v0.2.0
,
!7
l_p_loss and lrdecay implementation
Pipeline
#25683
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/helpers.py
+48
-0
48 additions, 0 deletions
src/helpers.py
with
48 additions
and
0 deletions
src/helpers.py
+
48
−
0
View file @
feb1aa56
...
...
@@ -2,7 +2,55 @@ __author__ = 'Lukas Leufen'
__date__
=
'
2019-10-21
'
import
logging
import
keras
import
keras.backend
as
K
import
math
def
to_list
(
arg
):
if
not
isinstance
(
arg
,
list
):
arg
=
[
arg
]
return
arg
class
Loss
:
def
l_p_loss
(
self
,
power
):
def
loss
(
y_true
,
y_pred
):
return
K
.
mean
(
K
.
pow
(
K
.
abs
(
y_pred
-
y_true
),
power
),
axis
=-
1
)
return
loss
class
lrDecay
(
keras
.
callbacks
.
History
):
def
__init__
(
self
,
base_lr
:
float
=
0.01
,
drop
:
float
=
0.96
,
epochs_drop
:
int
=
8
):
super
(
lrDecay
,
self
).
__init__
()
self
.
lr
=
{
'
lr
'
:
[]}
self
.
base_lr
=
base_lr
self
.
drop
=
drop
self
.
epochs_drop
=
epochs_drop
def
on_epoch_begin
(
self
,
epoch
:
int
,
logs
=
None
):
if
epoch
>
0
:
current_lr
=
self
.
base_lr
*
math
.
pow
(
self
.
drop
,
math
.
floor
(
1
+
epoch
)
/
self
.
epochs_drop
)
else
:
current_lr
=
self
.
base_lr
K
.
set_value
(
self
.
model
.
optimizer
.
lr
,
current_lr
)
self
.
lr
[
'
lr
'
].
append
(
current_lr
)
logging
.
info
(
f
"
Set learning rate to
{
current_lr
}
"
)
return
K
.
get_value
(
self
.
model
.
optimizer
.
lr
)
class
lrCallback
(
keras
.
callbacks
.
History
):
def
__init__
(
self
):
super
(
lrCallback
,
self
).
__init__
()
self
.
lr
=
None
def
on_train_begin
(
self
,
logs
=
None
):
self
.
lr
=
{}
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
self
.
lr
.
append
(
self
.
model
.
optimizer
.
lr
)
\ No newline at end of file
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