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
f6efd5db
Commit
f6efd5db
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Pass accessors, not paths, to model generator
parent
72b15b18
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/transfer_labels_to_ilastik_object_classifier.py
+4
-3
4 additions, 3 deletions
.../examples/transfer_labels_to_ilastik_object_classifier.py
extensions/chaeo/models.py
+17
-18
17 additions, 18 deletions
extensions/chaeo/models.py
with
21 additions
and
21 deletions
extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py
+
4
−
3
View file @
f6efd5db
...
...
@@ -54,6 +54,7 @@ def infer_and_compare(classifier: PatchStackObjectClassifier, prefix, raw, mask,
print
(
'
Truth and inferred labels match?
'
)
print
(
pd
.
value_counts
(
df_comp
[
'
truth_label
'
]
==
df_comp
[
'
inferred_label
'
]))
if
__name__
==
'
__main__
'
:
root
=
Path
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231030-0002
'
)
template_ilp
=
Path
(
'
c:/Users/rhodes/projects/proj0011-plankton-seg/exp0014/template_obj.ilp
'
)
...
...
@@ -67,9 +68,9 @@ if __name__ == '__main__':
classifier_file
=
generate_ilastik_object_classifier
(
template_ilp
,
root
/
'
new_auto_obj.ilp
'
,
root
/
'
zstack_train_raw.tif
'
,
root
/
'
zstack_train_mask.tif
'
,
root
/
'
zstack_train_label.tif
'
,
MonoPatchStackFromFile
(
root
/
'
zstack_train_raw.tif
'
)
,
MonoPatchStackFromFile
(
root
/
'
zstack_train_mask.tif
'
)
,
MonoPatchStackFromFile
(
root
/
'
zstack_train_label.tif
'
)
,
label_names
,
)
classifier
=
PatchStackObjectClassifier
({
'
project_file
'
:
classifier_file
})
...
...
This diff is collapsed.
Click to expand it.
extensions/chaeo/models.py
+
17
−
18
View file @
f6efd5db
...
...
@@ -7,7 +7,6 @@ import vigra
from
extensions.chaeo.accessors
import
MonoPatchStack
,
MonoPatchStackFromFile
from
extensions.ilastik.models
import
IlastikObjectClassifierFromSegmentationModel
from
model_server.accessors
import
InMemoryDataAccessor
class
PatchStackObjectClassifier
(
IlastikObjectClassifierFromSegmentationModel
):
...
...
@@ -50,9 +49,9 @@ class PatchStackObjectClassifier(IlastikObjectClassifierFromSegmentationModel):
def
generate_ilastik_object_classifier
(
template_ilp
:
Path
,
target_ilp
:
Path
,
raw_
tif
:
Path
,
mask_
tif
:
Path
,
label_
tif
:
Path
,
raw_
stack
:
MonoPatchStackFromFile
,
mask_
stack
:
MonoPatchStackFromFile
,
label_
stack
:
MonoPatchStackFromFile
,
label_names
:
list
,
lane
:
int
=
0
,
)
->
Path
:
...
...
@@ -60,27 +59,27 @@ def generate_ilastik_object_classifier(
Starting with a template project file, transfer input data and labels to a new project file.
:param template_ilp: path to existing ilastik object classifier to use as a template
:param target_ilp: path to new classifier
:param raw_
tif: path to
stack of patches containing raw data
:param mask_
tif: path to
stack of patches containing object masks
:param label_
tif: path to
stack of patches containing object labels
:param raw_
stack:
stack of patches containing raw data
:param mask_
stack:
stack of patches containing object masks
:param label_
stack:
stack of patches containing object labels
:param label_names: list of label names
:param lane: ilastik lane identifier
:return: path to generated object classifier
"""
assert
mask_stack
.
shape
==
raw_stack
.
shape
assert
label_stack
.
shape
==
raw_stack
.
shape
new_ilp
=
shutil
.
copy
(
template_ilp
,
target_ilp
)
path
s
=
{
'
Raw Data
'
:
raw_
tif
,
'
Segmentation Image
'
:
mask_
tif
,
accessor
s
=
{
'
Raw Data
'
:
raw_
stack
,
'
Segmentation Image
'
:
mask_
stack
,
}
root
=
raw_tif
.
parent
accessors
=
{
k
:
MonoPatchStackFromFile
(
root
/
pa
)
for
k
,
pa
in
paths
.
items
()}
# get labels from label image
acc_labels
=
MonoPatchStackFromFile
(
label_tif
)
labels
=
[]
for
ii
in
range
(
0
,
acc_
label
s
.
count
):
unique
=
np
.
unique
(
acc_
label
s
.
iat
(
ii
))
for
ii
in
range
(
0
,
label
_stack
.
count
):
unique
=
np
.
unique
(
label
_stack
.
iat
(
ii
))
assert
len
(
unique
)
>=
2
,
'
Label image contains more than one non-zero value
'
assert
unique
[
0
]
==
0
,
'
Label image does not contain unlabeled background
'
assert
unique
[
-
1
]
<
len
(
label_names
)
+
1
,
f
'
Label ID
{
unique
[
-
1
]
}
exceeds number of label names:
{
len
(
label_names
)
}
'
...
...
@@ -94,14 +93,14 @@ def generate_ilastik_object_classifier(
# set path to input image files
del
h5
[
f
'
{
group
}
/filePath
'
]
h5
[
f
'
{
group
}
/filePath
'
]
=
paths
[
gk
]
.
name
h5
[
f
'
{
group
}
/filePath
'
]
=
accessors
[
gk
].
fpath
.
name
assert
not
Path
(
h5
[
f
'
{
group
}
/filePath
'
][()].
decode
()).
is_absolute
()
assert
h5
[
f
'
{
group
}
/filePath
'
][()]
==
paths
[
gk
]
.
name
.
encode
()
assert
h5
[
f
'
{
group
}
/filePath
'
][()]
==
accessors
[
gk
].
fpath
.
name
.
encode
()
assert
h5
[
f
'
{
group
}
/location
'
][()]
==
'
FileSystem
'
.
encode
()
# set input nickname
del
h5
[
f
'
{
group
}
/nickname
'
]
h5
[
f
'
{
group
}
/nickname
'
]
=
paths
[
gk
]
.
stem
h5
[
f
'
{
group
}
/nickname
'
]
=
accessors
[
gk
].
fpath
.
stem
# set input shape
del
h5
[
f
'
{
group
}
/shape
'
]
...
...
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