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
f8dd4aa2
Commit
f8dd4aa2
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Abstractified Model base class
parent
ca9709e6
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/api.py
+1
-26
1 addition, 26 deletions
model_server/api.py
model_server/model.py
+14
-4
14 additions, 4 deletions
model_server/model.py
tests/test_model.py
+4
-0
4 additions, 0 deletions
tests/test_model.py
with
19 additions
and
30 deletions
model_server/api.py
+
1
−
26
View file @
f8dd4aa2
...
...
@@ -47,29 +47,4 @@ def infer_img(model_id: str, imgf: str, channel: int = None) -> dict:
channel
=
channel
)
session
.
record_workflow_run
(
record
)
return
record
# model = session.models[model_id]
#
# # read image file into memory
# # maybe this isn't accurate if e.g. czifile loads lazily
# t0 = time()
# img = generate_file_accessor(session.inbound / imgf)
# dt_fi = time() - t0
#
# # run model inference
# outdata, record = model.infer(img.data, channel=channel)
# dt_inf = time() - t0
#
# # write output to file
# outpath = session.outbound / img.fpath.stem / '.tif'
# WriteableTiffFileAccessor(outpath).write(outdata)
# dt_fo = time() - t0
#
# record['output_file'] = outpath
# record['times'] = {
# 'file_input': dt_fi,
# 'inference': dt_inf - dt_fi,
# 'file_output': dt_fo - dt_fi - dt_inf
# }
# session.register_inference(record)
\ No newline at end of file
return
record
\ No newline at end of file
This diff is collapsed.
Click to expand it.
model_server/model.py
+
14
−
4
View file @
f8dd4aa2
from
abc
import
ABC
,
abstractmethod
from
math
import
floor
import
numpy
as
np
from
model_server.image
import
GenericImageFileAccessor
# TODO: properly abstractify base class
class
Model
(
object
):
class
Model
(
ABC
):
def
__init__
(
self
,
autoload
=
True
):
"""
...
...
@@ -15,10 +15,11 @@ class Model(object):
"""
self
.
autoload
=
autoload
#
abstract
@
abstract
method
def
load
(
self
):
pass
@abstractmethod
def
infer
(
self
,
img
:
GenericImageFileAccessor
,
channel
:
int
=
None
...
...
@@ -33,7 +34,16 @@ class Model(object):
def
reload
(
self
):
self
.
load
()
class
ImageToImageModel
(
Model
):
# receives an image and returns an image of the same size
class
ImageToImageModel
(
Model
):
def
__init__
(
self
,
**
kwargs
):
"""
Abstract class for models that receive an image and return an image of the same size
:param kwargs: variable length keyword arguments
"""
return
super
(
**
kwargs
)
@abstractmethod
def
infer
(
self
,
img
,
channel
=
None
)
->
(
np
.
ndarray
,
dict
):
super
().
infer
(
img
,
channel
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_model.py
+
4
−
0
View file @
f8dd4aa2
...
...
@@ -7,6 +7,10 @@ class TestCziImageFileAccess(unittest.TestCase):
def
setUp
(
self
)
->
None
:
self
.
cf
=
CziImageFileAccessor
(
czifile
[
'
path
'
])
def
test_instantiate_model_with_nondefault_kwarg
(
self
):
model
=
DummyImageToImageModel
(
autoload
=
False
)
self
.
assertFalse
(
model
.
autoload
,
'
Could not override autoload flag in subclass of Model.
'
)
def
test_czifile_is_correct_shape
(
self
):
model
=
DummyImageToImageModel
()
img
,
_
=
model
.
infer
(
self
.
cf
,
channel
=
1
)
...
...
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