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
e5616b9b
Commit
e5616b9b
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
simple test for l_p_loss
parent
feb1aa56
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
#25704
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers.py
+4
-6
4 additions, 6 deletions
src/helpers.py
test/test_helpers.py
+17
-0
17 additions, 0 deletions
test/test_helpers.py
with
21 additions
and
6 deletions
src/helpers.py
+
4
−
6
View file @
e5616b9b
...
@@ -14,12 +14,10 @@ def to_list(arg):
...
@@ -14,12 +14,10 @@ def to_list(arg):
return
arg
return
arg
class
Loss
:
def
l_p_loss
(
power
):
def
loss
(
y_true
,
y_pred
):
def
l_p_loss
(
self
,
power
):
return
K
.
mean
(
K
.
pow
(
K
.
abs
(
y_pred
-
y_true
),
power
),
axis
=-
1
)
def
loss
(
y_true
,
y_pred
):
return
loss
return
K
.
mean
(
K
.
pow
(
K
.
abs
(
y_pred
-
y_true
),
power
),
axis
=-
1
)
return
loss
class
lrDecay
(
keras
.
callbacks
.
History
):
class
lrDecay
(
keras
.
callbacks
.
History
):
...
...
This diff is collapsed.
Click to expand it.
test/test_helpers.py
0 → 100644
+
17
−
0
View file @
e5616b9b
import
pytest
from
src.helpers
import
l_p_loss
import
logging
import
os
import
keras
import
keras.backend
as
K
import
numpy
as
np
class
TestLoss
:
def
test_l_p_loss
(
self
):
model
=
keras
.
Sequential
()
model
.
add
(
keras
.
layers
.
Lambda
(
lambda
x
:
x
,
input_shape
=
(
None
,
)))
model
.
compile
(
optimizer
=
keras
.
optimizers
.
Adam
(),
loss
=
l_p_loss
(
2
))
hist
=
model
.
fit
(
np
.
array
([
1
,
0
]),
np
.
array
([
1
,
1
]),
epochs
=
1
)
assert
hist
.
history
[
'
loss
'
][
0
]
==
0.5
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