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
c3e3ff61
Commit
c3e3ff61
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Test covers instance segmentation base class
parent
16d96d55
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
model_server/models.py
+21
-2
21 additions, 2 deletions
model_server/models.py
tests/test_model.py
+18
-11
18 additions, 11 deletions
tests/test_model.py
with
39 additions
and
13 deletions
model_server/models.py
+
21
−
2
View file @
c3e3ff61
...
...
@@ -90,8 +90,7 @@ class InstanceSegmentationModel(ImageToImageModel):
raise
InvalidInputImageError
(
'
Expect input image and mask to be the same shape
'
)
class
DummySegmentationModel
(
SemanticSegmentationModel
):
class
DummySemanticSegmentationModel
(
SemanticSegmentationModel
):
model_id
=
'
dummy_make_white_square
'
...
...
@@ -111,6 +110,26 @@ class DummySegmentationModel(SemanticSegmentationModel):
mask
,
_
=
self
.
infer
(
img
)
return
mask
class
DummyInstanceSegmentationModel
(
InstanceSegmentationModel
):
model_id
=
'
dummy_pass_input_mask
'
def
load
(
self
):
return
True
def
infer
(
self
,
img
:
GenericImageDataAccessor
,
mask
:
GenericImageDataAccessor
)
->
(
GenericImageDataAccessor
,
dict
):
return
mask
def
label_instance_class
(
self
,
img
:
GenericImageDataAccessor
,
mask
:
GenericImageDataAccessor
,
**
kwargs
)
->
GenericImageDataAccessor
:
"""
Returns a trivial segmentation, i.e. the input mask
"""
super
(
DummyInstanceSegmentationModel
,
self
).
label_instance_class
(
img
,
mask
,
**
kwargs
)
return
self
.
infer
(
img
,
mask
)
class
Error
(
Exception
):
pass
...
...
This diff is collapsed.
Click to expand it.
tests/test_model.py
+
18
−
11
View file @
c3e3ff61
import
unittest
from
conf.testing
import
czifile
from
model_server.accessors
import
CziImageFileAccessor
from
model_server.models
import
DummySegmentationModel
,
CouldNotLoadModelError
from
model_server.models
import
DummySe
manticSegmentationModel
,
DummyInstanceSe
gmentationModel
,
CouldNotLoadModelError
class
TestCziImageFileAccess
(
unittest
.
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
def
test_instantiate_model
(
self
):
model
=
DummySegmentationModel
(
params
=
None
)
model
=
DummySe
manticSe
gmentationModel
(
params
=
None
)
self
.
assertTrue
(
model
.
loaded
)
def
test_instantiate_model_with_nondefault_kwarg
(
self
):
model
=
DummySegmentationModel
(
autoload
=
False
)
model
=
DummySe
manticSe
gmentationModel
(
autoload
=
False
)
self
.
assertFalse
(
model
.
autoload
,
'
Could not override autoload flag in subclass of Model.
'
)
def
test_raise_error_if_cannot_load_model
(
self
):
class
UnloadableDummyImageToImageModel
(
DummySegmentationModel
):
class
UnloadableDummyImageToImageModel
(
DummySe
manticSe
gmentationModel
):
def
load
(
self
):
return
False
with
self
.
assertRaises
(
CouldNotLoadModelError
):
mi
=
UnloadableDummyImageToImageModel
()
def
test_czifile_is_correct_shape
(
self
):
model
=
DummySegmentationModel
()
img
,
_
=
model
.
infer
(
self
.
cf
)
def
test_dummy_pixel_segmentation
(
self
):
model
=
DummySemanticSegmentationModel
()
img
=
self
.
cf
.
get_one_channel_data
(
0
)
mask
=
model
.
label_pixel_class
(
img
)
w
=
czifile
[
'
w
'
]
h
=
czifile
[
'
h
'
]
self
.
assertEqual
(
img
.
shape
,
mask
.
shape
,
(
h
,
w
,
1
,
1
),
'
Inferred image is not the expected shape
'
)
self
.
assertEqual
(
img
.
data
[
int
(
w
/
2
),
int
(
h
/
2
)],
mask
.
data
[
int
(
w
/
2
),
int
(
h
/
2
)],
255
,
'
Middle pixel is not white as expected
'
)
self
.
assertEqual
(
img
.
data
[
0
,
0
],
mask
.
data
[
0
,
0
],
0
,
'
First pixel is not black as expected
'
)
\ No newline at end of file
)
return
img
,
mask
def
test_dummy_instance_segmentation
(
self
):
img
,
mask
=
self
.
test_dummy_pixel_segmentation
()
model
=
DummyInstanceSegmentationModel
()
obmap
=
model
.
label_instance_class
(
img
,
mask
)
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