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
b8bd1a91
Commit
b8bd1a91
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Renamed a few output files
parent
5aca68af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+17
-19
17 additions, 19 deletions
.../examples/transfer_labels_to_ilastik_object_classifier.py
with
17 additions
and
19 deletions
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+
17
−
19
View file @
b8bd1a91
...
@@ -8,7 +8,6 @@ import skimage
...
@@ -8,7 +8,6 @@ import skimage
import
uuid
import
uuid
import
vigra
import
vigra
from
extensions.chaeo.util
import
autonumber_new_file
from
extensions.ilastik.models
import
IlastikObjectClassifierFromSegmentationModel
from
extensions.ilastik.models
import
IlastikObjectClassifierFromSegmentationModel
from
model_server.accessors
import
generate_file_accessor
,
GenericImageDataAccessor
,
InMemoryDataAccessor
,
write_accessor_data_to_file
from
model_server.accessors
import
generate_file_accessor
,
GenericImageDataAccessor
,
InMemoryDataAccessor
,
write_accessor_data_to_file
...
@@ -88,7 +87,13 @@ def get_dataset_info(h5: h5py.File, lane : int = 0):
...
@@ -88,7 +87,13 @@ def get_dataset_info(h5: h5py.File, lane : int = 0):
return
info
return
info
def
generate_ilastik_object_classifier
(
template_ilp
:
str
,
where
:
str
,
stack_name
:
str
=
'
train
'
,
lane
:
int
=
0
):
def
generate_ilastik_object_classifier
(
template_ilp
:
str
,
where
:
str
,
stack_name
:
str
=
'
train
'
,
lane
:
int
=
0
,
proj_name
=
'
auto_obj
'
):
"""
"""
Starting with a template project file, transfer input data and labels to a duplicate project file.
Starting with a template project file, transfer input data and labels to a duplicate project file.
...
@@ -134,11 +139,11 @@ def generate_ilastik_object_classifier(template_ilp: str, where: str, stack_name
...
@@ -134,11 +139,11 @@ def generate_ilastik_object_classifier(template_ilp: str, where: str, stack_name
assert
info
[
hg
][
'
location
'
]
==
b
'
FileSystem
'
assert
info
[
hg
][
'
location
'
]
==
b
'
FileSystem
'
assert
info
[
hg
][
'
axes
'
]
==
[
'
t
'
,
'
y
'
,
'
x
'
]
assert
info
[
hg
][
'
axes
'
]
==
[
'
t
'
,
'
y
'
,
'
x
'
]
new_ilp
=
shutil
.
copy
(
template_ilp
,
root
/
autonumber_new_file
(
root
,
'
auto-obj
'
,
'
ilp
'
))
new_ilp
=
shutil
.
copy
(
template_ilp
,
where
/
(
proj_name
+
'
.
ilp
'
))
# write to new project file
# write to new project file
lns
=
f
'
{
lane
:
04
d
}
'
lns
=
f
'
{
lane
:
04
d
}
'
with
h5py
.
File
(
new_ilp
,
'
r+
'
)
as
h5
:
with
h5py
.
File
(
where
/
new_ilp
,
'
r+
'
)
as
h5
:
def
set_ds
(
grp
,
ds
,
val
):
def
set_ds
(
grp
,
ds
,
val
):
ds
=
h5
[
f
'
Input Data/infos/lane
{
lns
}
/
{
grp
}
/
{
ds
}
'
]
ds
=
h5
[
f
'
Input Data/infos/lane
{
lns
}
/
{
grp
}
/
{
ds
}
'
]
ds
[()]
=
val
ds
[()]
=
val
...
@@ -193,7 +198,7 @@ def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageD
...
@@ -193,7 +198,7 @@ def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageD
ob_id
=
skimage
.
measure
.
label
(
inf_img
)
ob_id
=
skimage
.
measure
.
label
(
inf_img
)
pr
=
skimage
.
measure
.
regionprops_table
(
ob_id
,
properties
=
[
'
label
'
,
'
area
'
])
pr
=
skimage
.
measure
.
regionprops_table
(
ob_id
,
properties
=
[
'
label
'
,
'
area
'
])
mask
=
inf_img
==
pr
[
'
label
'
][
pr
[
'
area
'
].
argmax
()]
mask
=
inf_img
==
pr
[
'
label
'
][
pr
[
'
area
'
].
argmax
()]
dd
[
'
inferred_label
'
]
=
np
.
unique
(
mask
*
inf_img
)[
1
]
dd
[
'
inferred_label
'
]
=
np
.
unique
(
mask
*
inf_img
)[
-
1
]
# occasionally no object in frame
dd
[
'
multiples
'
]
=
True
dd
[
'
multiples
'
]
=
True
else
:
# exactly one unique object class in frame
else
:
# exactly one unique object class in frame
dd
[
'
inferred_label
'
]
=
unique
[
1
]
dd
[
'
inferred_label
'
]
=
unique
[
1
]
...
@@ -203,13 +208,14 @@ def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageD
...
@@ -203,13 +208,14 @@ def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageD
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
root
=
Path
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/
'
)
root
=
Path
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/
'
)
template_ilp
=
root
/
'
exp0014/template_obj.ilp
'
template_ilp
=
root
/
'
exp0014/template_obj.ilp
'
where_patch_stack
=
root
/
'
exp0009/output/labeled_patches-20231018-000
1
'
where_patch_stack
=
root
/
'
exp0009/output/labeled_patches-20231018-000
5
'
# auto-populate an object classifier
# auto-populate an object classifier
new
_ilp
=
generate_ilastik_object_classifier
(
auto
_ilp
=
generate_ilastik_object_classifier
(
template_ilp
,
template_ilp
,
where_patch_stack
,
where_patch_stack
,
stack_name
=
'
train
'
stack_name
=
'
train
'
,
proj_name
=
'
auto_obj_before
'
)
)
def
infer_and_compare
(
ilp
,
suffix
):
def
infer_and_compare
(
ilp
,
suffix
):
...
@@ -223,24 +229,16 @@ if __name__ == '__main__':
...
@@ -223,24 +229,16 @@ if __name__ == '__main__':
# write comparison tables
# write comparison tables
train_truth_labels
=
generate_file_accessor
(
where_patch_stack
/
f
'
zstack_train_label.tif
'
)
train_truth_labels
=
generate_file_accessor
(
where_patch_stack
/
f
'
zstack_train_label.tif
'
)
df_comp
=
compare_object_maps
(
train_truth_labels
,
result_acc
)
df_comp
=
compare_object_maps
(
train_truth_labels
,
result_acc
)
df_comp
.
to_csv
(
df_comp
.
to_csv
(
where_patch_stack
/
f
'
compare_train_result_
{
suffix
}
.csv
'
,
index
=
False
)
where_patch_stack
/
autonumber_new_file
(
where_patch_stack
,
f
'
compare_train_result_
{
suffix
}
'
,
'
csv
'
),
index
=
False
)
print
(
f
'
Generated ilastik project
{
ilp
}
'
)
print
(
f
'
Generated ilastik project
{
ilp
}
'
)
print
(
'
Truth and inferred labels match?
'
)
print
(
'
Truth and inferred labels match?
'
)
print
(
pd
.
value_counts
(
df_comp
[
'
truth_label
'
]
==
df_comp
[
'
inferred_label
'
]))
print
(
pd
.
value_counts
(
df_comp
[
'
truth_label
'
]
==
df_comp
[
'
inferred_label
'
]))
# infer object labels from the same data used to train the classifier
# infer object labels from the same data used to train the classifier
infer_and_compare
(
new
_ilp
,
'
before
'
)
infer_and_compare
(
auto
_ilp
,
'
before
'
)
# copy project and prompt user input once ilastik file has been modified in-app
# copy project and prompt user input once ilastik file has been modified in-app
mod_ilp
=
shutil
.
copy
(
mod_ilp
=
shutil
.
copy
(
auto_ilp
,
where_patch_stack
/
'
auto_obj_after.ilp
'
)
new_ilp
,
where_patch_stack
/
autonumber_new_file
(
where_patch_stack
,
'
auto-obj
'
,
'
ilp
'
)
)
print
(
f
'
Press enter when project file
{
mod_ilp
}
has been updated in ilastik
'
)
print
(
f
'
Press enter when project file
{
mod_ilp
}
has been updated in ilastik
'
)
input
()
input
()
...
...
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