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
cd51beaa
Commit
cd51beaa
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Still trying to get autogenerated object classifier working by messing with HDF5
parent
672218ca
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
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+39
-12
39 additions, 12 deletions
.../examples/transfer_labels_to_ilastik_object_classifier.py
with
39 additions
and
12 deletions
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+
39
−
12
View file @
cd51beaa
...
...
@@ -98,7 +98,7 @@ def generate_ilastik_object_classifier(
Starting with a template project file, transfer input data and labels to a duplicate project file.
:param template_ilp: absolute path to existing ilastik object classifier to use as a template
:param where:
location of
folder containing input data, segmentation maps, labels, and label descriptions
:param where:
absolute path to
folder containing input data, segmentation maps, labels, and label descriptions
:poram stack_name: prefix of .tif and .csv files that contain classifier training data (e.g. train, test)
:param lane: ilastik lane identifier
:return: (str) name of new ilastik classifier project file
...
...
@@ -106,12 +106,12 @@ def generate_ilastik_object_classifier(
# validate z-stack input data
root
=
Path
(
where
)
paths
=
{
'
Raw Data
'
:
root
/
f
'
zstack_
{
stack_name
}
_raw.tif
'
,
'
Segmentation Image
'
:
root
/
f
'
zstack_
{
stack_name
}
_mask.tif
'
,
rel_
paths
=
{
'
Raw Data
'
:
Path
(
f
'
zstack_
{
stack_name
}
_raw.tif
'
)
,
'
Segmentation Image
'
:
Path
(
f
'
zstack_
{
stack_name
}
_mask.tif
'
)
,
}
accessors
=
{
k
:
generate_file_accessor
(
pa
)
for
k
,
pa
in
paths
.
items
()}
accessors
=
{
k
:
generate_file_accessor
(
root
/
pa
)
for
k
,
pa
in
rel_
paths
.
items
()}
assert
accessors
[
'
Raw Data
'
].
chroma
==
1
assert
accessors
[
'
Segmentation Image
'
].
is_mask
()
...
...
@@ -153,23 +153,39 @@ def generate_ilastik_object_classifier(
return
df_patches
.
loc
[
df_patches
.
zi
==
idx
,
'
annotation_class_id
'
].
iat
[
0
]
for
hg
in
[
'
Raw Data
'
,
'
Segmentation Image
'
]:
set_ds
(
hg
,
'
filePath
'
,
paths
[
hg
].
__str__
())
set_ds
(
hg
,
'
nickname
'
,
paths
[
hg
].
stem
)
set_ds
(
hg
,
'
filePath
'
,
rel_
paths
[
hg
].
__str__
())
set_ds
(
hg
,
'
nickname
'
,
rel_
paths
[
hg
].
stem
)
shape_zyx
=
[
accessors
[
hg
].
shape_dict
[
ax
]
for
ax
in
[
'
Z
'
,
'
Y
'
,
'
X
'
]]
set_ds
(
hg
,
'
shape
'
,
np
.
array
(
shape_zyx
))
# change key of label names
del
h5
[
'
ObjectClassification/LabelNames
'
]
if
(
k_ln
:
=
'
ObjectClassification/LabelNames
'
)
in
h5
.
keys
():
del
h5
[
k_ln
]
ln
=
np
.
array
(
label_names
)
h5
.
create_dataset
(
'
ObjectClassification/LabelNames
'
,
data
=
ln
.
astype
(
'
O
'
))
h5
.
create_dataset
(
k_ln
,
data
=
ln
.
astype
(
'
O
'
))
if
(
k_mn
:
=
'
ObjectClassification/MaxNumObj
'
)
in
h5
.
keys
():
del
h5
[
k_mn
]
# h5.create_dataset(k_mn, data=(len(label_names) - 1))
h5
[
k_mn
]
=
len
(
label_names
)
-
1
del
h5
[
'
currentApplet
'
]
h5
[
'
currentApplet
'
]
=
1
# change object labels
la_groupname
=
f
'
ObjectClassification/LabelInputs/
{
lns
}
'
del
h5
[
la_groupname
]
lag
=
h5
.
create_group
(
la_groupname
)
if
(
k_li
:
=
f
'
ObjectClassification/LabelInputs/
{
lns
}
'
)
in
h5
.
keys
():
del
h5
[
k_li
]
lag
=
h5
.
create_group
(
k_li
)
for
zi
in
range
(
0
,
nz
):
lag
[
f
'
{
zi
}
'
]
=
np
.
array
([
0.
,
float
(
get_label
(
zi
))])
# delete existing classification weights
if
(
k_rf
:
=
f
'
ObjectExtraction/RegionFeatures/
{
lane
:
04
d
}
'
)
in
h5
.
keys
():
del
h5
[
k_rf
]
if
(
k_cf
:
=
'
ObjectClassification/ClassificationForests
'
)
in
h5
.
keys
():
del
h5
[
k_cf
]
return
new_ilp
def
compare_object_maps
(
truth
:
GenericImageDataAccessor
,
inferred
:
GenericImageDataAccessor
)
->
pd
.
DataFrame
:
...
...
@@ -218,6 +234,7 @@ if __name__ == '__main__':
proj_name
=
'
auto_obj_before
'
)
def
infer_and_compare
(
ilp
,
suffix
):
# infer object labels from the same data used to train the classifier
train_zstack_raw
=
generate_file_accessor
(
where_patch_stack
/
'
zstack_train_raw.tif
'
)
...
...
@@ -234,6 +251,16 @@ if __name__ == '__main__':
print
(
'
Truth and inferred labels match?
'
)
print
(
pd
.
value_counts
(
df_comp
[
'
truth_label
'
]
==
df_comp
[
'
inferred_label
'
]))
# report out some things for debugging
rks
=
[
'
ObjectClassification/MaxNumObj
'
,
'
ObjectClassification/LabelInputs/0000/0
'
,
'
currentApplet
'
]
with
h5py
.
File
(
ilp
,
'
r
'
)
as
h5
:
for
r
in
rks
:
print
(
f
'
{
r
}
:
{
h5
[
r
][()]
}
'
)
# infer object labels from the same data used to train the classifier
infer_and_compare
(
auto_ilp
,
'
before
'
)
...
...
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