Skip to content
Snippets Groups Projects
Commit 571657a4 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Example script with 3D ilastik model

parent f36da7c8
No related branches found
No related tags found
No related merge requests found
from multiprocessing import Process
from pathlib import Path
import requests
from shutil import copyfile
import uvicorn
host = '127.0.0.1'
port = 5001
px3d_ilp = '3d_model/px3d.ilp'
ob3d_ilp = '3d_model/ob3d.ilp'
czi_root = Path('z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0036')
czis = [
'A01-selection-test01.czi',
'B01-selection-test01.czi'
]
channel = 4
if __name__ == '__main__':
server_process = Process(
target=uvicorn.run,
args=('api:app',),
kwargs={'host': host, 'port': port, 'log_level': 'debug'},
daemon=True
)
uri = f'http://{host}:{port}/'
server_process.start()
resp_paths = requests.get(uri + 'paths')
paths = resp_paths.json()
# load ilastik pixel model
resp_load_px = requests.put(
uri + 'models/ilastik/pixel_classification/load/',
params={'project_file': px3d_ilp},
)
assert resp_load_px.status_code == 200
model_id_px = resp_load_px.json()['model_id']
# load ilastik object model
resp_load_ob = requests.put(
uri + 'models/ilastik/object_classification/load/',
params={'project_file': ob3d_ilp},
)
assert resp_load_ob.status_code == 200
model_id_ob = resp_load_ob.json()['model_id']
# copy files from network storage to processing directory
for ff in czis:
infile = Path(czi_root) / ff
outfile = Path(paths['inbound_images']) / ff
copyfile(infile, outfile)
# infer pixel maps
resp_infer_px = requests.put(
uri + f'infer/from_image_file',
params={
'model_id': model_id_px,
'input_filename': ff,
'channel': channel,
},
)
assert resp_infer_px == 200
# infer object maps
resp_infer_ob = requests.put(
uri + f'infer/from_image_file',
params={
'model_id': model_id_ob,
'input_filename': ff,
'channel': channel,
},
)
assert resp_infer_px == 200
resp_models = requests.get(uri + 'models')
server_process.terminate()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment