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
648455f3
Commit
648455f3
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Aborted bringing ndarray labels into data accessor superclass
parent
d44b8073
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
model_server/ilastik.py
+5
-0
5 additions, 0 deletions
model_server/ilastik.py
model_server/image.py
+47
-24
47 additions, 24 deletions
model_server/image.py
tests/test_ilastik.py
+7
-3
7 additions, 3 deletions
tests/test_ilastik.py
tests/test_image.py
+11
-3
11 additions, 3 deletions
tests/test_image.py
with
70 additions
and
30 deletions
model_server/ilastik.py
+
5
−
0
View file @
648455f3
...
...
@@ -22,8 +22,13 @@ class IlastikImageToImageModel(ImageToImageModel):
if
'
project_file
'
not
in
params
or
not
os
.
path
.
exists
(
params
[
'
project_file
'
]):
raise
ParameterExpectedError
(
'
Ilastik model expects a project (*.ilp) file
'
)
self
.
project_file
=
str
(
params
[
'
project_file
'
])
self
.
shell
=
None
self
.
operator
=
None
super
().
__init__
(
autoload
,
params
)
def
__del__
(
self
):
self
.
shell
.
closeCurrentProject
()
def
load
(
self
):
os
.
environ
[
"
LAZYFLOW_THREADS
"
]
=
"
8
"
os
.
environ
[
"
LAZYFLOW_TOTAL_RAM_MB
"
]
=
"
24000
"
...
...
This diff is collapsed.
Click to expand it.
model_server/image.py
+
47
−
24
View file @
648455f3
...
...
@@ -12,15 +12,27 @@ class GenericImageDataAccessor(ABC):
valid_keys
=
[
'
X
'
,
'
Y
'
,
'
C
'
,
'
Z
'
]
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
data
,
shape_dict
,
**
kwargs
):
"""
Abstract base class that exposes an interfaces for image data, irrespective of whether it is instantiated
from file I/O or other means.
:param kwargs: variable-length keyword arguments
"""
self
.
_data
=
None
self
.
_shape_dict
=
None
if
shape_dict
[
'
S
'
]
>
1
or
shape_dict
[
'
T
'
]
>
1
:
raise
FileShapeError
(
f
'
Cannot handle image with multiple positions or time points:
{
shape_dict
}
'
)
if
any
([
k
not
in
self
.
valid_keys
for
k
in
shape_dict
.
keys
()]):
raise
InvalidAxisKey
(
f
'
Invalid keys:
{
shape_dict
.
keys
}
'
)
self
.
_shape_dict
=
shape_dict
self
.
_data
=
data
self
.
data
=
np
.
moveaxis
(
cf
.
asarray
(),
[
cf
.
axes
.
index
(
ch
)
for
ch
in
self
.
shape_dict
],
[
0
,
1
,
2
,
3
]
).
squeeze
()
@property
def
chroma
(
self
):
...
...
@@ -31,23 +43,31 @@ class GenericImageDataAccessor(ABC):
@property
def
data
(
self
):
return
self
.
_data
return
np
.
moveaxis
(
cf
.
asarray
(),
[
cf
.
axes
.
index
(
ch
)
for
ch
in
self
.
shape_dict
],
[
0
,
1
,
2
,
3
]
).
squeeze
()
@data.setter
def
data
(
self
,
data_arg
):
if
len
(
data_arg
.
shape
)
>
4
:
raise
InvalidDataShape
(
f
'
Invalid data shape:
{
data_arg
.
shape
}
'
)
self
.
_data
=
data_arg
#
@data.setter
#
def data(self, data_arg):
#
if len(data_arg.shape) > 4:
#
raise InvalidDataShape(f'Invalid data shape: {data_arg.shape}')
#
self._data = data_arg
@property
def
shape_dict
(
self
):
return
self
.
_shape_dict
@shape_dict.setter
def
shape_dict
(
self
,
dict_arg
:
Dict
[
str
,
int
]):
if
any
([
k
not
in
self
.
valid_keys
for
k
in
dict_arg
.
keys
()]):
raise
InvalidAxisKey
(
f
'
Invalid keys:
{
dict_arg
}
'
)
self
.
_shape_dict
=
dict_arg
# @shape_dict.setter
# def shape_dict(self, dict_arg: Dict[str, int]):
# if any([k not in self.valid_keys for k in dict_arg.keys()]):
# raise InvalidAxisKey(f'Invalid keys: {dict_arg}')
# self._shape_dict = dict_arg
def
get_one_channel
(
self
):
ci
=
self
.
shape_dict
[
'
C
'
]
return
self
.
data
[]
class
GenericImageFileAccessor
(
GenericImageDataAccessor
):
# image data is loaded from a file
def
__init__
(
self
,
fpath
:
Path
,
**
kwargs
):
...
...
@@ -74,16 +94,19 @@ class CziImageFileAccessor(GenericImageFileAccessor):
except
:
raise
FileAccessorError
(
f
'
Unable to access data in
{
fpath
}
'
)
sd
=
{
ch
:
cf
.
shape
[
cf
.
axes
.
index
(
ch
)]
for
ch
in
cf
.
axes
}
if
sd
[
'
S
'
]
>
1
or
sd
[
'
T
'
]
>
1
:
raise
FileShapeError
(
f
'
Cannot handle image with multiple positions or time points:
{
sd
}
'
)
self
.
shape_dict
=
{
k
:
sd
[
k
]
for
k
in
[
'
X
'
,
'
Y
'
,
'
C
'
,
'
Z
'
]}
self
.
data
=
np
.
moveaxis
(
cf
.
asarray
(),
[
cf
.
axes
.
index
(
ch
)
for
ch
in
self
.
shape_dict
],
[
0
,
1
,
2
,
3
]
).
squeeze
()
self
.
shape_dict
=
{
ch
:
cf
.
shape
[
cf
.
axes
.
index
(
ch
)]
for
ch
in
cf
.
axes
}
self
.
data
=
cf
.
asarray
()
# sd = {ch: cf.shape[cf.axes.index(ch)] for ch in cf.axes}
# if sd['S'] > 1 or sd['T'] > 1:
# raise FileShapeError(f'Cannot handle image with multiple positions or time points: {sd}')
#
# self.shape_dict = {k: sd[k] for k in ['X', 'Y', 'C', 'Z']}
# self.data = np.moveaxis(
# cf.asarray(),
# [cf.axes.index(ch) for ch in self.shape_dict],
# [0, 1, 2, 3]
# ).squeeze()
...
...
This diff is collapsed.
Click to expand it.
tests/test_ilastik.py
+
7
−
3
View file @
648455f3
...
...
@@ -7,13 +7,17 @@ class TestIlastikPixelClassification(unittest.TestCase):
def
setUp
(
self
)
->
None
:
self
.
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
# def tearDown(self) -> None:
# pass
def
test_faulthandler
(
self
):
# recreate error that is messing up ilastik
import
io
import
sys
import
faulthandler
print
(
sys
.
stdout
)
print
(
sys
.
stderr
)
faulthandler
.
enable
(
file
=
sys
.
stdout
)
with
self
.
assertRaises
(
io
.
UnsupportedOperation
):
faulthandler
.
enable
(
file
=
sys
.
stdout
)
def
test_instantiate_pixel_classifier
(
self
):
model
=
IlastikPixelClassifierModel
({
'
project_file
'
:
ilastik
[
'
pixel_classifier
'
]})
This diff is collapsed.
Click to expand it.
tests/test_image.py
+
11
−
3
View file @
648455f3
import
unittest
from
conf.testing
import
czifile
from
model_server.image
import
CziImageFileAccessor
from
conf.testing
import
czifile
,
output_path
from
model_server.image
import
CziImageFileAccessor
,
WriteableTiffFileAccessor
class
TestCziImageFileAccess
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
...
...
@@ -11,4 +11,12 @@ class TestCziImageFileAccess(unittest.TestCase):
self
.
assertEqual
(
cf
.
shape_dict
[
'
Y
'
],
czifile
[
'
h
'
])
self
.
assertEqual
(
cf
.
shape_dict
[
'
X
'
],
czifile
[
'
w
'
])
self
.
assertEqual
(
cf
.
chroma
,
czifile
[
'
c
'
])
self
.
assertFalse
(
cf
.
is_3d
())
\ No newline at end of file
self
.
assertFalse
(
cf
.
is_3d
())
def
test_write_single_channel_tif
(
self
):
ch
=
4
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
of
=
WriteableTiffFileAccessor
(
output_path
/
f
'
{
cf
.
fpath
.
stem
}
_ch
{
ch
}
.tif
'
)
of
.
write
(
cf
.
data
[])
\ 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