Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mu-map
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tamino Huxohl
mu-map
Commits
828569e1
"git@gitlab.ub.uni-bielefeld.de:ramin.yaghoubzadeh/ipaaca.git" did not exist on "07ebd969926bffe1464220abdb0bbad273b4e3c0"
Commit
828569e1
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
implement comparator functions for weighted loss and normalization transform
parent
ff167f5d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mu_map/dataset/normalization.py
+18
-1
18 additions, 1 deletion
mu_map/dataset/normalization.py
mu_map/training/loss.py
+28
-1
28 additions, 1 deletion
mu_map/training/loss.py
with
46 additions
and
2 deletions
mu_map/dataset/normalization.py
+
18
−
1
View file @
828569e1
...
...
@@ -2,7 +2,7 @@
Module containing normalization methods either as functions
or transformers.
"""
from
typing
import
Callable
,
Optional
,
Tuple
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
from
torch
import
Tensor
...
...
@@ -69,6 +69,23 @@ class NormTransform(Transform):
"""
return
(
self
.
norm_func
(
tensors
[
0
]),
*
tensors
[
1
:])
def
__eq__
(
self
,
other
:
Any
)
->
bool
:
"""
Implementation of the comparison operator.
This implementation just checks that self and other are of
the same class.
Parameters
----------
other: Any
Returns
-------
bool
"""
return
self
.
__class__
==
other
.
__class__
class
MaxNormTransform
(
NormTransform
):
"""
...
...
This diff is collapsed.
Click to expand it.
mu_map/training/loss.py
+
28
−
1
View file @
828569e1
from
typing
import
List
from
typing
import
Any
,
List
import
torch
import
torch.nn
as
nn
...
...
@@ -68,6 +68,33 @@ class WeightedLoss(nn.Module):
map
(
lambda
x
:
f
"
{
x
[
0
]
:
.
3
f
}
*
{
x
[
1
]
}
"
,
zip
(
self
.
weights
,
self
.
losses
))
)
def
__eq__
(
self
,
other
:
Any
)
->
bool
:
"""
Implementation of the comparison operator.
This implementation makes sure that both weighted losses consist
of the same loss classes with the same weights. Note that this
is not a `smart` implementation as the order matters. For example,
`L2+GDL` is not equal to `GDL+L2`.
Parameters
----------
other: Any
Returns
-------
bool
"""
if
self
.
__class__
!=
other
.
__class__
:
return
False
if
len
(
self
.
losses
)
!=
len
(
other
.
losses
):
return
False
loss_classes_self
=
tuple
(
map
(
lambda
loss
:
loss
.
__class__
,
self
.
losses
))
loss_classes_other
=
tuple
(
map
(
lambda
loss
:
loss
.
__class__
,
other
.
losses
))
return
loss_classes_self
==
loss_classes_other
and
self
.
weights
==
other
.
weights
@classmethod
def
from_str
(
cls
,
loss_func_str
:
str
):
"""
...
...
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