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
7f82c049
Commit
7f82c049
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Pixel map generation passes test, confirmed image orientation and format are correct
parent
4634eb4e
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
model_server/ilastik.py
+13
-11
13 additions, 11 deletions
model_server/ilastik.py
model_server/image.py
+6
-1
6 additions, 1 deletion
model_server/image.py
tests/test_ilastik.py
+31
-12
31 additions, 12 deletions
tests/test_ilastik.py
with
50 additions
and
24 deletions
model_server/ilastik.py
+
13
−
11
View file @
7f82c049
...
...
@@ -7,6 +7,7 @@ from ilastik.workflows.pixelClassification import PixelClassificationWorkflow
from
ilastik.workflows.objectClassification.objectClassificationWorkflow
import
ObjectClassificationWorkflow
import
numpy
as
np
import
vigra
from
model_server.image
import
GenericImageDataAccessor
,
InMemoryDataAccessor
from
model_server.model
import
ImageToImageModel
,
ParameterExpectedError
...
...
@@ -14,11 +15,6 @@ from model_server.model import ImageToImageModel, ParameterExpectedError
class
IlastikImageToImageModel
(
ImageToImageModel
):
# workflows = {
# 'pixel_classification': PixelClassificationWorkflow,
# 'object_classification': ObjectClassificationWorkflow,
# }
def
__init__
(
self
,
params
,
autoload
=
True
):
if
'
project_file
'
not
in
params
or
not
os
.
path
.
exists
(
params
[
'
project_file
'
]):
raise
ParameterExpectedError
(
'
Ilastik model expects a project (*.ilp) file
'
)
...
...
@@ -56,20 +52,26 @@ class IlastikImageToImageModel(ImageToImageModel):
return
workflow
.
objectClassificationApplet
.
topLevelOperator
# def infer(self, img, channel=None) -> (np.ndarray, dict):
# assert self.operator.Classifier.ready()
class
IlastikPixelClassifierModel
(
IlastikImageToImageModel
):
workflow
=
PixelClassificationWorkflow
def
infer
(
self
,
input_img
:
GenericImageDataAccessor
,
channel
=
None
)
->
(
np
.
ndarray
,
dict
):
tagged_input_data
=
vigra
.
taggedView
(
input_img
.
data
,
'
xycz
'
)
dsi
=
[
{
'
Raw Data
'
:
PreloadedArrayDatasetInfo
(
preloaded_array
=
input_img
.
data
[
0
:
3
]
),
'
Raw Data
'
:
PreloadedArrayDatasetInfo
(
preloaded_array
=
tagged_input_data
),
}
]
pxmaps
=
self
.
shell
.
workflow
.
batchProcessingApplet
.
run_export
(
dsi
,
export_to_array
=
True
)
return
InMemoryDataAccessor
(
data
=
pxmaps
[
0
])
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
'
)
xycz
=
np
.
moveaxis
(
pxmaps
[
0
],
[
2
,
1
,
3
,
0
],
[
0
,
1
,
2
,
3
]
)
return
InMemoryDataAccessor
(
data
=
xycz
)
This diff is collapsed.
Click to expand it.
model_server/image.py
+
6
−
1
View file @
7f82c049
...
...
@@ -95,7 +95,12 @@ class CziImageFileAccessor(GenericImageFileAccessor):
def
write_accessor_data_to_file
(
fpath
:
Path
,
accessor
:
GenericImageDataAccessor
)
->
bool
:
try
:
tifffile
.
imwrite
(
fpath
,
accessor
.
data
)
zcxy
=
np
.
moveaxis
(
accessor
.
data
,
[
3
,
2
,
0
,
1
],
[
0
,
1
,
2
,
3
]
)
tifffile
.
imwrite
(
fpath
,
zcxy
,
imagej
=
True
)
except
:
raise
FileWriteError
(
f
'
Unable to write data to file
'
)
return
True
...
...
This diff is collapsed.
Click to expand it.
tests/test_ilastik.py
+
31
−
12
View file @
7f82c049
import
unittest
import
numpy
as
np
from
conf.testing
import
czifile
,
ilastik
,
output_path
from
model_server.image
import
CziImageFileAccessor
,
write_accessor_data_to_file
from
model_server.image
import
CziImageFileAccessor
,
InMemoryDataAccessor
,
write_accessor_data_to_file
from
model_server.ilastik
import
IlastikPixelClassifierModel
class
TestIlastikPixelClassification
(
unittest
.
TestCase
):
...
...
@@ -18,21 +21,37 @@ class TestIlastikPixelClassification(unittest.TestCase):
with
self
.
assertRaises
(
io
.
UnsupportedOperation
):
faulthandler
.
enable
(
file
=
sys
.
stdout
)
def
test_run_pixel_classifier_on_random_data
(
self
):
model
=
IlastikPixelClassifierModel
({
'
project_file
'
:
ilastik
[
'
pixel_classifier
'
]})
w
=
512
h
=
256
input_img
=
InMemoryDataAccessor
(
data
=
np
.
random
.
rand
(
w
,
h
,
1
,
1
))
pxmap
=
model
.
infer
(
input_img
)
self
.
assertEqual
(
pxmap
.
shape
,
(
w
,
h
,
2
,
1
))
def
test_run_pixel_classifier
(
self
):
channel
=
2
model
=
IlastikPixelClassifierModel
({
'
project_file
'
:
ilastik
[
'
pixel_classifier
'
]})
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
pxmap
=
model
.
infer
(
cf
.
get_one_channel_data
(
channel
))
mono_image
=
cf
.
get_one_channel_data
(
channel
)
self
.
assertEqual
(
mono_image
.
shape_dict
[
'
X
'
],
czifile
[
'
w
'
])
self
.
assertEqual
(
mono_image
.
shape_dict
[
'
Y
'
],
czifile
[
'
h
'
])
self
.
assertEqual
(
mono_image
.
shape_dict
[
'
C
'
],
1
)
self
.
assertEqual
(
mono_image
.
shape_dict
[
'
Z
'
],
1
)
pxmap
=
model
.
infer
(
mono_image
)
self
.
assertEqual
(
pxmap
.
shape
[
0
:
2
],
cf
.
shape
[
0
:
2
])
self
.
assertEqual
(
pxmap
.
shape_dict
[
'
C
'
],
2
)
self
.
assertEqual
(
pxmap
.
shape_dict
[
'
Z
'
],
1
)
print
(
pxmap
.
shape_dict
)
self
.
assertTrue
(
write_accessor_data_to_file
(
output_path
/
f
'
pxmap_
{
cf
.
fpath
.
stem
}
_ch
{
channel
}
.tif
'
,
pxmap
)
)
# self.assertEqual(pxmap.shape[0:2], cf.shape[0:2])
# self.assertEqual(pxmap.shape_dict['C'], 2)
# self.assertEqual(pxmap.shape_dict['Z'], 1)
#
# self.assertTrue(
# write_accessor_data_to_file(
# output_path / f'pxmap_{cf.fpath.stem}_ch{channel}.tif',
# pxmap
# )
# )
\ No newline at end of file
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