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
043aa390
Commit
043aa390
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Added docstrings
parent
30f37e0b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
clients/examples/run_simple_ilastik.py
+4
-0
4 additions, 0 deletions
clients/examples/run_simple_ilastik.py
clients/ilastik_map_objects_simple.py
+62
-51
62 additions, 51 deletions
clients/ilastik_map_objects_simple.py
clients/imagej/adapter.py
+20
-3
20 additions, 3 deletions
clients/imagej/adapter.py
with
86 additions
and
54 deletions
clients/examples/run_simple_ilastik.py
+
4
−
0
View file @
043aa390
"""
Debug a client request sequence from the same environment as the server
"""
from
clients.util
import
get_client
from
clients
import
ilastik_map_objects_simple
...
...
This diff is collapsed.
Click to expand it.
clients/ilastik_map_objects_simple.py
+
62
−
51
View file @
043aa390
from
os.path
import
basename
,
dirname
from
os.path
import
basename
,
dirname
def
main
(
request_func
,
in_abspath
,
params
):
"""
Execute a sequence of client requests that load ilastik pixel and object classifiers, then infer on an image file
:param request_func: (func) function that implements HTTP client, dependent on which environment request are called from
:param in_abspath: (str) absolute path to image file to infer
:param params:
pixel_classifier_path: (str) absolute path to ilastik project file that defines a pixel classifier
object_classifier_path: (str) absolute path to ilastik project file that defines an object classifier
channel: (int) channel of the input image to process
:return: (str) absolute path where a new object map is written
"""
where
=
dirname
(
in_abspath
)
in_file
=
basename
(
in_abspath
)
...
...
@@ -9,59 +20,59 @@ def main(request_func, in_abspath, params):
ob_ilp
=
params
[
'
object_classifier_path
'
]
channel
=
params
[
'
channel
'
]
# configure input and output paths
resp
=
request_func
(
'
PUT
'
,
# configure input and output paths
resp
=
request_func
(
'
PUT
'
,
'
/paths/watch_input
'
,
{
'
path
'
:
where
,
}
)
assert
resp
[
'
status
'
]
==
200
,
'
Error setting up image directory
'
{
'
path
'
:
where
,
}
)
assert
resp
[
'
status
'
]
==
200
,
'
Error setting up image directory
'
resp
=
request_func
(
'
PUT
'
,
'
/paths/watch_output
'
,
{
'
path
'
:
where
,
}
)
assert
resp
[
'
status
'
]
==
200
,
'
Error setting up image directory
'
# load pixel classifier
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/px/load/
'
,
{
'
project_file
'
:
px_ilp
,
'
duplicate
'
:
False
,
},
)
resp
=
request_func
(
'
PUT
'
,
'
/paths/watch_output
'
,
{
'
path
'
:
where
,
}
)
assert
resp
[
'
status
'
]
==
200
,
'
Error setting up image directory
'
# load pixel classifier
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/px/load/
'
,
{
'
project_file
'
:
px_ilp
,
'
duplicate
'
:
False
,
},
)
assert
resp
[
'
status
'
],
'
Error loading classifier:
'
+
px_ilp
id_px_mod
=
resp
[
'
content
'
][
'
model_id
'
]
# load object classifier
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/pxmap_to_obj/load/
'
,
{
'
project_file
'
:
ob_ilp
,
'
duplicate
'
:
False
,
},
)
assert
resp
[
'
status
'
]
==
200
,
'
Error loading object classifier:
'
+
{
ob_ilp
}
id_ob_mod
=
resp
[
'
content
'
][
'
model_id
'
]
# run inference
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/pixel_then_object_classification/infer
'
,
{
'
px_model_id
'
:
id_px_mod
,
'
ob_model_id
'
:
id_ob_mod
,
'
input_filename
'
:
in_file
,
'
channel
'
:
channel
,
}
# load object classifier
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/pxmap_to_obj/load/
'
,
{
'
project_file
'
:
ob_ilp
,
'
duplicate
'
:
False
,
},
)
assert
resp
[
'
status
'
]
==
200
,
'
Error loading object classifier:
'
+
{
ob_ilp
}
id_ob_mod
=
resp
[
'
content
'
][
'
model_id
'
]
# run inference
resp
=
request_func
(
'
PUT
'
,
'
/ilastik/pixel_then_object_classification/infer
'
,
{
'
px_model_id
'
:
id_px_mod
,
'
ob_model_id
'
:
id_ob_mod
,
'
input_filename
'
:
in_file
,
'
channel
'
:
channel
,
}
)
assert
resp
[
'
status
'
]
==
200
,
'
Error calling workfow
'
return
resp
[
'
content
'
][
'
object_map_filepath
'
]
return
resp
[
'
content
'
][
'
object_map_filepath
'
]
This diff is collapsed.
Click to expand it.
clients/imagej/adapter.py
+
20
−
3
View file @
043aa390
"""
Functionality needed to run a client request sequence (clients.*.main) in the ImageJ python 2.7 script environment
"""
import
httplib
import
json
import
urllib
...
...
@@ -9,6 +13,13 @@ PORT = 6221
uri
=
'
http://{}:{}/
'
.
format
(
HOST
,
PORT
)
def
hit_endpoint
(
method
,
endpoint
,
params
=
None
):
"""
Python 2.7 implementation of HTTP client
:param method: (str) either
'
GET
'
or
'
PUT
'
:param endpoint: (str) endpoint of HTTP request
:param params: (dict) of parameters required by client request
:return: (dict) of response status and content, formatted as dict if request is successful
"""
connection
=
httplib
.
HTTPConnection
(
HOST
,
PORT
)
if
not
method
in
[
'
GET
'
,
'
PUT
'
]:
raise
Exception
(
'
Can only handle GET and PUT requests
'
)
...
...
@@ -23,10 +34,16 @@ def hit_endpoint(method, endpoint, params=None):
content
=
json
.
loads
(
resp_str
)
except
Exception
:
content
=
{
'
str
'
:
str
(
resp_str
)}
return
{
'
status
'
:
resp
.
status
,
'
content
'
:
content
}
return
{
'
status
'
:
resp
.
status
,
'
content
'
:
content
}
def
run_request_sequence
(
imp
,
module
,
params
):
def
run_request_sequence
(
imp
,
func
,
params
):
"""
Execute a sequence of client requests in the ImageJ scripting environment
:param imp: (ij.ImagePlus) input image
:param func: (func) function that implements client request sequence
:param params: (dict) parameters specific to client request
:return: (ij.ImagePlus) output image
"""
in_path
=
imp
.
getProp
(
'
Location
'
)
out_path
=
func
(
hit_endpoint
,
in_path
,
params
)
return
ImagePlus
(
out_path
)
\ 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