Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySegCNN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
earth_observation_public
PySegCNN
Commits
3a60f332
Commit
3a60f332
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Added LabelMapping from Sparcs to Alcd and vice versa.
parent
8f6b2d2a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/core/constants.py
+72
-0
72 additions, 0 deletions
pysegcnn/core/constants.py
with
72 additions
and
0 deletions
pysegcnn/core/constants.py
+
72
−
0
View file @
3a60f332
...
@@ -169,3 +169,75 @@ class Gdal2Numpy(enum.Enum):
...
@@ -169,3 +169,75 @@ class Gdal2Numpy(enum.Enum):
CInt32
=
np
.
complex64
CInt32
=
np
.
complex64
CFloat32
=
np
.
complex64
CFloat32
=
np
.
complex64
CFloat64
=
np
.
complex64
CFloat64
=
np
.
complex64
# class label mapping from the Sparcs dataset to the Alcd dataset
Sparcs2Alcd
=
LabelMapping
({
SparcsLabels
.
Shadow
.
id
:
AlcdLabels
.
Shadow
.
id
,
SparcsLabels
.
Shadow_over_water
:
AlcdLabels
.
Shadow
.
id
,
SparcsLabels
.
Water
.
id
:
AlcdLabels
.
Water
.
id
,
SparcsLabels
.
Snow
.
id
:
AlcdLabels
.
Snow
.
id
,
SparcsLabels
.
Land
.
id
:
AlcdLabels
.
Land
.
id
,
SparcsLabels
.
Cloud
.
id
:
AlcdLabels
.
Cloud
.
id
,
SparcsLabels
.
Flooded
.
id
:
AlcdLabels
.
Land
.
id
,
SparcsLabels
.
No_data
.
id
:
AlcdLabels
.
No_data
.
id
})
# class label mapping from the Alcd dataset to the Sparcs dataset
Alcd2Sparcs
=
LabelMapping
({
AlcdLabels
.
No_data
.
id
:
SparcsLabels
.
No_data
.
id
,
AlcdLabels
.
Not_used
.
id
:
SparcsLabels
.
No_data
.
id
,
AlcdLabels
.
Cloud
.
id
:
SparcsLabels
.
Cloud
.
id
,
AlcdLabels
.
Cirrus
.
id
:
SparcsLabels
.
Cloud
.
id
,
AlcdLabels
.
Shadow
.
id
:
SparcsLabels
.
Shadow
.
id
,
AlcdLabels
.
Land
.
id
:
SparcsLabels
.
Land
.
id
,
AlcdLabels
.
Water
.
id
:
SparcsLabels
.
Water
.
id
,
AlcdLabels
.
Snow
.
id
:
SparcsLabels
.
Snow
.
id
})
def
map_labels
(
source
,
target
):
"""
Map labels from a source domain to a target domain.
Parameters
----------
source : :py:class:`pysegcnn.core.constants.Label`
The source domain labels, i.e. the labels a model is trained with.
target : :py:class:`pysegcnn.core.constants.Label`
The target domain labels, i.e. the labels of the dataset to apply the
model to.
Raises
------
ValueError
Raised if no label mapping from ``source`` to ``target`` is defined.
Returns
-------
label_map : :py:class:`pysegcnn.core.constants.LabelMapping` [`int`, `int`]
Dictionary with source labels as keys and corresponding target labels
as values.
"""
# if source and target labels are equal, the label mapping is the
# identity
if
source
is
target
:
label_map
=
None
# mapping from Sparcs to Alcd
elif
source
is
SparcsLabels
and
target
is
AlcdLabels
:
label_map
=
Sparcs2Alcd
# mapping from Alcd to Sparcs
elif
source
is
AlcdLabels
and
target
is
SparcsLabels
:
label_map
=
Alcd2Sparcs
else
:
raise
ValueError
(
'
Unknown label mapping from {} to {}
'
.
format
(
source
.
__name__
,
target
.
__name__
))
return
label_map
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