Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TaggingBackends
Manage
Activity
Members
Labels
Plan
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nyx
TaggingBackends
Commits
06aa49ad
Commit
06aa49ad
authored
2 years ago
by
François LAURENT
Browse files
Options
Downloads
Patches
Plain Diff
Labels.encode and Labels.decode reworked; version increment
parent
4b68a149
No related branches found
No related tags found
No related merge requests found
Pipeline
#95769
passed
2 years ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Project.toml
+1
-1
1 addition, 1 deletion
Project.toml
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
src/taggingbackends/data/labels.py
+40
-17
40 additions, 17 deletions
src/taggingbackends/data/labels.py
with
42 additions
and
19 deletions
Project.toml
+
1
−
1
View file @
06aa49ad
name
=
"TaggingBackends"
uuid
=
"e551f703-3b82-4335-b341-d497b48d519b"
authors
=
[
"François Laurent"
,
"Institut Pasteur"
]
version
=
"0.
7.2
"
version
=
"0.
8
"
[deps]
Dates
=
"ade2ca70-3891-5945-98fb-dc099432e06a"
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
06aa49ad
[tool.poetry]
name
=
"TaggingBackends"
version
=
"0.
7.2
"
version
=
"0.
8
"
description
=
"Backbone for LarvaTagger.jl tagging backends"
authors
=
[
"François Laurent"
]
...
...
This diff is collapsed.
Click to expand it.
src/taggingbackends/data/labels.py
+
40
−
17
View file @
06aa49ad
...
...
@@ -309,32 +309,55 @@ class Labels:
for
timestamp
,
label
in
zip
(
track
[
"
t
"
],
track
[
"
labels
"
])}
return
self
def
encode
(
self
,
labels
):
"""
Encode the text labels as indices (`int` or `list` of `int`).
Labels are 1-indexed. If shifted down, the indices apply to attribute
`labelspec`.
"""
def
encode
(
self
,
label
=
None
):
if
label
is
None
:
encoded
=
label
=
self
for
run_larva
in
label
:
label
[
run_larva
]
=
self
.
encode
(
label
[
run_larva
])
elif
isinstance
(
label
,
dict
):
encoded
=
{
t
:
self
.
encode
(
l
)
for
t
,
l
in
label
.
items
()}
else
:
if
isinstance
(
self
.
labelspec
,
dict
):
labelset
=
self
.
labelspec
[
"
names
"
]
labelset
=
self
.
labelspec
[
'
names
'
]
else
:
labelset
=
self
.
labelspec
encoded
=
[]
for
label
in
labels
:
if
isinstance
(
label
,
str
):
encoded
.
append
(
labelset
.
index
(
label
)
+
1
)
encoded
=
labelset
.
index
(
label
)
+
1
elif
isinstance
(
label
,
int
):
encoded
=
label
logging
.
debug
(
'
label(s) already encoded
'
)
else
:
encoded
.
append
(
[
labelset
.
index
(
l
abel
)
+
1
for
l
abel
in
label
]
)
encoded
=
[
labelset
.
index
(
l
)
+
1
for
l
in
label
]
return
encoded
"""
Decode the label indices as text (`str` or `list` of `str`).
Text labels are picked in `labelspec`.
"""
def
decode
(
self
,
label
=
None
):
if
isinstance
(
self
.
labelspec
,
dict
):
labelset
=
self
.
labelspec
[
"
names
"
]
else
:
labelset
=
self
.
labelspec
if
label
is
None
:
label
=
decoded
=
self
decoded
=
label
=
self
for
run_larva
in
label
:
label
[
run_larva
]
=
self
.
decode
(
label
[
run_larva
])
elif
isinstance
(
label
,
dict
):
decoded
=
{
t
:
labelset
[
l
-
1
]
for
t
,
l
in
label
.
items
()}
elif
isinstance
(
label
,
int
):
decoded
=
{
t
:
self
.
decode
(
l
)
for
t
,
l
in
label
.
items
()}
else
:
if
isinstance
(
self
.
labelspec
,
dict
):
labelset
=
self
.
labelspec
[
'
names
'
]
else
:
labelset
=
self
.
labelspec
if
isinstance
(
label
,
int
):
decoded
=
labelset
[
label
-
1
]
elif
isinstance
(
label
,
str
):
decoded
=
label
logging
.
debug
(
'
label(s) already decoded
'
)
else
:
decoded
=
[
labelset
[
l
-
1
]
for
l
in
label
]
return
decoded
...
...
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