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
b17d32c6
Commit
b17d32c6
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Retained object classification from pixel probabilitie
parent
bbc607cc
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/ilastik/models.py
+44
-20
44 additions, 20 deletions
extensions/ilastik/models.py
model_server/accessors.py
+2
-0
2 additions, 0 deletions
model_server/accessors.py
with
46 additions
and
20 deletions
extensions/ilastik/models.py
+
44
−
20
View file @
b17d32c6
...
...
@@ -6,7 +6,7 @@ import vigra
import
extensions.ilastik.conf
from
model_server.accessors
import
GenericImageDataAccessor
,
InMemoryDataAccessor
from
model_server.models
import
Model
,
InstanceSegmentationModel
,
ParameterExpectedError
,
SemanticSegmentationModel
from
model_server.models
import
Model
,
ImageToImageModel
,
InstanceSegmentationModel
,
InvalidInputImageError
,
ParameterExpectedError
,
SemanticSegmentationModel
class
IlastikModel
(
Model
):
...
...
@@ -82,23 +82,24 @@ class IlastikPixelClassifierModel(IlastikModel, SemanticSegmentationModel):
mask
=
pxmap
.
data
[:,
:,
pixel_class
,
:]
>
pixel_probability_threshold
return
InMemoryDataAccessor
(
mask
)
# TODO: deprecate
class
IlastikObjectClassifierFrom
PixelPredic
tion
s
Model
(
IlastikModel
):
model_id
=
'
ilastik_object_classification_from_
pixel_predic
tion
s
'
class
IlastikObjectClassifierFrom
Segmenta
tionModel
(
IlastikModel
,
InstanceSegmentationModel
):
model_id
=
'
ilastik_object_classification_from_
segmenta
tion
'
@staticmethod
def
get_workflow
():
from
ilastik.workflows.objectClassification.objectClassificationWorkflow
import
ObjectClassificationWorkflow
Prediction
return
ObjectClassificationWorkflow
Prediction
from
ilastik.workflows.objectClassification.objectClassificationWorkflow
import
ObjectClassificationWorkflow
Binary
return
ObjectClassificationWorkflow
Binary
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
pxmap_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
segmentation_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
assert
segmentation_img
.
is_mask
()
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
yxcz
'
)
tagged_
pxmap
_data
=
vigra
.
taggedView
(
pxmap
_img
.
data
,
'
yxcz
'
)
tagged_
seg
_data
=
vigra
.
taggedView
(
segmentation
_img
.
data
,
'
yxcz
'
)
dsi
=
[
{
'
Raw Data
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_input_data
),
'
Prediction Maps
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_
pxmap
_data
),
'
Segmentation Image
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_
seg
_data
),
}
]
...
...
@@ -113,24 +114,28 @@ class IlastikObjectClassifierFromPixelPredictionsModel(IlastikModel):
)
return
InMemoryDataAccessor
(
data
=
yxcz
),
{
'
success
'
:
True
}
def
label_instance_class
(
self
,
img
:
GenericImageDataAccessor
,
mask
:
GenericImageDataAccessor
,
**
kwargs
):
super
(
IlastikObjectClassifierFromSegmentationModel
,
self
).
label_instance_class
(
img
,
mask
,
**
kwargs
)
obmap
,
_
=
self
.
infer
(
img
,
mask
)
return
obmap
class
IlastikObjectClassifierFromSegmentationModel
(
IlastikModel
,
InstanceSegmentationModel
):
model_id
=
'
ilastik_object_classification_from_segmentation
'
class
IlastikObjectClassifierFromPixelPredictionsModel
(
IlastikModel
,
ImageToImageModel
):
model_id
=
'
ilastik_object_classification_from_pixel_predictions
'
@staticmethod
def
get_workflow
():
from
ilastik.workflows.objectClassification.objectClassificationWorkflow
import
ObjectClassificationWorkflow
Binary
return
ObjectClassificationWorkflow
Binary
from
ilastik.workflows.objectClassification.objectClassificationWorkflow
import
ObjectClassificationWorkflow
Prediction
return
ObjectClassificationWorkflow
Prediction
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
segmentation_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
assert
segmentation_img
.
is_mask
()
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
pxmap_img
:
GenericImageDataAccessor
)
->
(
np
.
ndarray
,
dict
):
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
yxcz
'
)
tagged_
seg
_data
=
vigra
.
taggedView
(
segmentation
_img
.
data
,
'
yxcz
'
)
tagged_
pxmap
_data
=
vigra
.
taggedView
(
pxmap
_img
.
data
,
'
yxcz
'
)
dsi
=
[
{
'
Raw Data
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_input_data
),
'
Segmentation Image
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_
seg
_data
),
'
Prediction Maps
'
:
self
.
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_
pxmap
_data
),
}
]
...
...
@@ -145,7 +150,26 @@ class IlastikObjectClassifierFromSegmentationModel(IlastikModel, InstanceSegment
)
return
InMemoryDataAccessor
(
data
=
yxcz
),
{
'
success
'
:
True
}
def
label_instance_class
(
self
,
img
:
GenericImageDataAccessor
,
mask
:
GenericImageDataAccessor
,
**
kwargs
):
super
(
IlastikObjectClassifierFromSegmentationModel
,
self
).
label_instance_class
(
img
,
mask
,
**
kwargs
)
def
label_instance_class
(
self
,
img
:
GenericImageDataAccessor
,
pxmap
:
GenericImageDataAccessor
,
**
kwargs
):
"""
Given an image and a map of pixel probabilities of the same shape, return a map where each connected object is
assigned a class.
:param img: input image
:param pxmap: map of pixel probabilities
:param kwargs:
pixel_classification_channel: channel of pxmap used to segment objects
pixel_classification_thresold: threshold of pxmap used to segment objects
:return:
"""
if
not
img
.
shape
==
pxmap
.
shape
:
raise
InvalidInputImageError
(
'
Expecting input image and pixel probabilities to be the same shape
'
)
# TODO: check that pxmap is in-range
pxch
=
kwargs
.
get
(
'
pixel_classification_channel
'
,
0
)
pxtr
=
kwargs
(
'
pixel_classification_threshold
'
,
0.5
)
mask
=
InMemoryDataAccessor
(
pxmap
.
get_one_channel_data
(
pxch
).
data
>
pxtr
)
# super(IlastikObjectClassifierFromSegmentationModel, self).label_instance_class(img, mask, **kwargs)
obmap
,
_
=
self
.
infer
(
img
,
mask
)
return
obmap
\ No newline at end of file
return
obmap
This diff is collapsed.
Click to expand it.
model_server/accessors.py
+
2
−
0
View file @
b17d32c6
...
...
@@ -34,6 +34,8 @@ class GenericImageDataAccessor(ABC):
def
is_3d
(
self
):
return
True
if
self
.
shape_dict
[
'
Z
'
]
>
1
else
False
# TODO: implement is_probability
def
is_mask
(
self
):
return
is_mask
(
self
.
_data
)
...
...
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