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
4d369c51
Commit
4d369c51
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Refined workflow class check
parent
3eb38020
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
conf/testing.py
+1
-0
1 addition, 0 deletions
conf/testing.py
model_server/ilastik.py
+33
-11
33 additions, 11 deletions
model_server/ilastik.py
tests/test_ilastik.py
+4
-1
4 additions, 1 deletion
tests/test_ilastik.py
with
38 additions
and
12 deletions
conf/testing.py
+
1
−
0
View file @
4d369c51
...
...
@@ -13,6 +13,7 @@ czifile = {
ilastik
=
{
'
pixel_classifier
'
:
root
/
'
testdata
'
/
'
pix02.ilp
'
,
'
object_classifier
'
:
root
/
'
testdata
'
/
'
obj01.ilp
'
,
}
output_path
=
root
/
'
testing_output
'
...
...
This diff is collapsed.
Click to expand it.
model_server/ilastik.py
+
33
−
11
View file @
4d369c51
...
...
@@ -20,7 +20,7 @@ class IlastikImageToImageModel(ImageToImageModel):
raise
ParameterExpectedError
(
'
Ilastik model expects a project (*.ilp) file
'
)
self
.
project_file
=
str
(
params
[
'
project_file
'
])
self
.
shell
=
None
self
.
operator
=
None
#
self.operator = None
super
().
__init__
(
autoload
,
params
)
def
__del__
(
self
):
...
...
@@ -35,27 +35,27 @@ class IlastikImageToImageModel(ImageToImageModel):
args
.
project
=
self
.
project_file
shell
=
app
.
main
(
args
)
if
shell
.
workflow
.
__class__
!=
self
.
workflow
:
if
not
isinstance
(
shell
.
workflow
,
self
.
workflow
)
:
raise
ParameterExpectedError
(
f
'
Ilastik project file
{
self
.
project_file
}
does not describe an instance of
{
shell
.
workflow
.
__class__
}
'
)
self
.
operator
=
self
.
get_top_level_operator
(
shell
.
workflow
)
#
self.operator = self.get_top_level_operator(shell.workflow)
self
.
shell
=
shell
return
True
@staticmethod
def
get_top_level_operator
(
workflow
):
if
isinstance
(
workflow
,
PixelClassificationWorkflow
):
return
workflow
.
pcApplet
.
topLevelOperator
elif
isinstance
(
workflow
,
ObjectClassificationWorkflow
):
return
workflow
.
objectClassificationApplet
.
topLevelOperator
#
@staticmethod
#
def get_top_level_operator(workflow):
#
if isinstance(workflow, PixelClassificationWorkflow):
#
return workflow.pcApplet.topLevelOperator
#
elif isinstance(workflow, ObjectClassificationWorkflow):
#
return workflow.objectClassificationApplet.topLevelOperator
class
IlastikPixelClassifierModel
(
IlastikImageToImageModel
):
workflow
=
PixelClassificationWorkflow
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
channel
=
None
)
->
(
np
.
ndarray
,
dict
):
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
xycz
'
)
dsi
=
[
{
...
...
@@ -64,7 +64,7 @@ class IlastikPixelClassifierModel(IlastikImageToImageModel):
]
pxmaps
=
self
.
shell
.
workflow
.
batchProcessingApplet
.
run_export
(
dsi
,
export_to_array
=
True
)
# [1 x w x h x n]
assert
(
len
(
pxmaps
)
==
1
,
'
ilastik generated more than on pixel map
'
)
assert
(
len
(
pxmaps
)
==
1
,
'
ilastik generated more than on
e
pixel map
'
)
xycz
=
np
.
moveaxis
(
pxmaps
[
0
],
...
...
@@ -73,5 +73,27 @@ class IlastikPixelClassifierModel(IlastikImageToImageModel):
)
return
InMemoryDataAccessor
(
data
=
xycz
),
{
'
success
'
:
True
}
class
IlastikObjectClassifierModel
(
IlastikImageToImageModel
):
workflow
=
ObjectClassificationWorkflow
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
pxmap_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
xycz
'
)
tagged_pxmap_data
=
vigra
.
taggedView
(
pxmap_img
.
data
,
'
xycz
'
)
dsi
=
[
{
'
Raw Data
'
:
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_input_data
),
'
Prediction Maps
'
:
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_pxmap_data
),
}
]
obmaps
=
self
.
shell
.
workflow
.
batchProcessingApplet
.
run_export
(
dsi
,
export_to_array
=
True
)
assert
(
len
(
obmaps
)
==
1
,
'
ilastik generated more than one object map
'
)
xycz
=
np
.
moveaxis
(
obmaps
[
0
],
[
2
,
1
,
3
,
0
],
[
0
,
1
,
2
,
3
]
)
return
InMemoryDataAccessor
(
data
=
xycz
),
{
'
success
'
:
True
}
This diff is collapsed.
Click to expand it.
tests/test_ilastik.py
+
4
−
1
View file @
4d369c51
...
...
@@ -4,7 +4,7 @@ import numpy as np
from
conf.testing
import
czifile
,
ilastik
,
output_path
from
model_server.image
import
CziImageFileAccessor
,
InMemoryDataAccessor
,
write_accessor_data_to_file
from
model_server.ilastik
import
IlastikPixelClassifierModel
from
model_server.ilastik
import
IlastikObjectClassifierModel
,
IlastikPixelClassifierModel
class
TestIlastikPixelClassification
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
...
...
@@ -65,3 +65,6 @@ class TestIlastikPixelClassification(unittest.TestCase):
)
)
def
test_run_object_classifier
(
self
):
model
=
IlastikObjectClassifierModel
({
'
project_file
'
:
ilastik
[
'
object_classifier
'
]})
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