Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ALMF
SVLT
Commits
75eacb9f
Commit
75eacb9f
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Apply labels to ilastik project file from training data
parent
215a8002
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extensions/chaeo/examples/label_patches.py
+1
-1
1 addition, 1 deletion
extensions/chaeo/examples/label_patches.py
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+24
-3
24 additions, 3 deletions
.../examples/transfer_labels_to_ilastik_object_classifier.py
with
25 additions
and
4 deletions
extensions/chaeo/examples/label_patches.py
+
1
−
1
View file @
75eacb9f
...
...
@@ -10,6 +10,6 @@ if __name__ == '__main__':
where_patches
=
(
root
/
'
batch-output-20231012-0016/2d_patches_training
'
).
__str__
(),
object_csv
=
(
root
/
'
batch-output-20231011-0003/df_objects.csv
'
).
__str__
(),
ecotaxa_tsv
=
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0013/ecotaxa_export_10468_20231012_0930.tsv
'
,
where_output
=
autonumber_new_directory
(
root
,
'
labeled_patches
'
)
where_output
=
autonumber_new_directory
(
root
,
'
labeled_patches
'
)
,
)
print
(
'
Finished
'
)
This diff is collapsed.
Click to expand it.
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+
24
−
3
View file @
75eacb9f
import
csv
from
pathlib
import
Path
import
h5py
import
ilastik.applets.objectClassification
import
numpy
as
np
import
pandas
as
pd
from
extensions.ilastik.models
import
IlastikObjectClassifierModel
...
...
@@ -8,16 +10,35 @@ from extensions.ilastik.models import IlastikObjectClassifierModel
def
transfer_labels_to_ilastik_ilp
(
ilp
,
df_stack_meta
):
with
h5py
.
File
(
ilp
,
'
r+
'
)
as
h5
:
where_out
=
Path
(
ilp
).
parent
# export complete HDF5 tree
with
open
(
where_out
/
'
h5tree.txt
'
,
'
w
'
)
as
hf
:
tt
=
[]
h5
.
visititems
(
lambda
k
,
v
:
tt
.
append
([
k
,
str
(
v
)]))
for
line
in
tt
:
hf
.
write
(
f
'
{
line
[
0
]
}
---
{
line
[
1
]
}
\n
'
)
h5
.
visititems
(
lambda
k
,
v
:
print
(
k
+
'
:
'
+
str
(
v
)))
# change key of label names
ln
=
[
'
none
'
]
+
list
(
df_stack_meta
.
sort_values
(
'
annotation_class_id
'
).
annotation_class
.
unique
())
del
h5
[
'
ObjectClassification/LabelNames
'
]
h5
.
create_dataset
(
'
ObjectClassification/LabelNames
'
,
data
=
np
.
array
(
ln
).
astype
(
'
O
'
))
# change object labels
ts
=
h5
[
'
ObjectClassification
'
][
'
LabelInputs
'
][
'
0000
'
]
for
ti
in
ts
.
items
():
idx
=
int
(
ti
[
0
])
assert
len
(
ti
)
==
2
# one for unlabeled area, one for labeled area
idx
=
int
(
ti
[
0
])
# important because keys are strings and hence not sorted numerically
ds
=
ti
[
1
]
la_old
=
ds
[
1
]
ds
[
1
]
=
float
(
df_stack_meta
.
loc
[
df_stack_meta
.
zi
==
idx
,
'
annotation_class_id
'
].
iat
[
0
])
# unit index, i.e. reserve 1 for no object
ds
[
1
]
=
float
(
1
+
df_stack_meta
.
loc
[
df_stack_meta
.
zi
==
idx
,
'
annotation_class_id
'
].
iat
[
0
])
print
(
f
'
Changed label
{
ti
}
from
{
la_old
}
to
{
ds
[
1
]
}
'
)
if
__name__
==
'
__main__
'
:
ilp
=
'
c:/Users/rhodes/model-server/ilastik/test_auto
mate_obj_labels
.ilp
'
ilp
=
'
c:/Users/rhodes/model-server/ilastik/test_auto
label_obj
.ilp
'
df
=
pd
.
read_csv
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231013-0022/training_stack.csv
'
)
...
...
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