Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
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
Christopher Randolph Rhodes
model_server
Commits
b99720e2
Commit
b99720e2
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Validate chroma and dimensionality of inputs to pixel classification model
parent
b15e0b2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!16
Completed (de)serialization of RoiSet
,
!5
Resolve "ilastik models do not validate dimensionality of input data"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
model_server/extensions/ilastik/models.py
+24
-0
24 additions, 0 deletions
model_server/extensions/ilastik/models.py
model_server/extensions/ilastik/tests/test_ilastik.py
+37
-0
37 additions, 0 deletions
model_server/extensions/ilastik/tests/test_ilastik.py
with
61 additions
and
0 deletions
model_server/extensions/ilastik/models.py
+
24
−
0
View file @
b99720e2
import
json
import
os
from
pathlib
import
Path
...
...
@@ -73,12 +74,31 @@ class IlastikPixelClassifierModel(IlastikModel, SemanticSegmentationModel):
model_id
=
'
ilastik_pixel_classification
'
operations
=
[
'
segment
'
,
]
@property
def
model_shape_dict
(
self
):
raw_info
=
self
.
shell
.
projectManager
.
currentProjectFile
[
'
Input Data
'
][
'
infos
'
][
'
lane0000
'
][
'
Raw Data
'
]
ax
=
raw_info
[
'
axistags
'
][()]
ax_keys
=
[
ax
[
'
key
'
].
upper
()
for
ax
in
json
.
loads
(
ax
)[
'
axes
'
]]
shape
=
raw_info
[
'
shape
'
][()]
return
dict
(
zip
(
ax_keys
,
shape
))
@property
def
model_chroma
(
self
):
return
self
.
model_shape_dict
[
'
C
'
]
@property
def
model_3d
(
self
):
return
self
.
model_shape_dict
[
'
Z
'
]
>
1
@staticmethod
def
get_workflow
():
from
ilastik.workflows
import
PixelClassificationWorkflow
return
PixelClassificationWorkflow
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
if
self
.
model_chroma
!=
input_img
.
chroma
or
self
.
model_3d
!=
input_img
.
is_3d
():
raise
IlastikInputShapeError
()
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
yxcz
'
)
dsi
=
[
{
...
...
@@ -221,4 +241,8 @@ class Error(Exception):
pass
class
IlastikInputEmbedding
(
Error
):
pass
class
IlastikInputShapeError
(
Error
):
"""
Raised when an ilastik classifier is asked to infer on data that is incompatible with its input shape
"""
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
model_server/extensions/ilastik/tests/test_ilastik.py
+
37
−
0
View file @
b99720e2
...
...
@@ -11,6 +11,9 @@ from model_server.base.roiset import _get_label_ids, RoiSet, RoiSetMetaParams
from
model_server.base.workflows
import
classify_pixels
from
tests.test_api
import
TestServerBaseClass
def
_random_int
(
*
args
):
return
np
.
random
.
randint
(
0
,
2
**
8
,
size
=
args
,
dtype
=
'
uint8
'
)
class
TestIlastikPixelClassification
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
...
...
@@ -83,6 +86,40 @@ class TestIlastikPixelClassification(unittest.TestCase):
self
.
mono_image
=
mono_image
self
.
mask
=
mask
def
test_pixel_classifier_enforces_input_shape
(
self
):
model
=
ilm
.
IlastikPixelClassifierModel
(
{
'
project_file
'
:
ilastik_classifiers
[
'
px
'
]}
)
self
.
assertEqual
(
model
.
model_chroma
,
1
)
self
.
assertEqual
(
model
.
model_3d
,
False
)
# correct data
self
.
assertIsInstance
(
model
.
label_pixel_class
(
InMemoryDataAccessor
(
_random_int
(
512
,
256
,
1
,
1
)
)
),
InMemoryDataAccessor
)
# raise except with input of multiple channels
with
self
.
assertRaises
(
ilm
.
IlastikInputShapeError
):
mask
=
model
.
label_pixel_class
(
InMemoryDataAccessor
(
_random_int
(
512
,
256
,
3
,
1
)
)
)
# raise except with input of multiple channels
with
self
.
assertRaises
(
ilm
.
IlastikInputShapeError
):
mask
=
model
.
label_pixel_class
(
InMemoryDataAccessor
(
_random_int
(
512
,
256
,
1
,
15
)
)
)
def
test_run_object_classifier_from_pixel_predictions
(
self
):
self
.
test_run_pixel_classifier
()
fp
=
czifile
[
'
path
'
]
...
...
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