diff --git a/api.py b/api.py index e62758b072db59306aeb149e4392343b0cca1bdd..03861c2dc48d7f072dd059138b00e2c89ad7094f 100644 --- a/api.py +++ b/api.py @@ -1,5 +1,3 @@ -from typing import Dict - from fastapi import FastAPI, HTTPException from model_server.ilastik import IlastikPixelClassifierModel, IlastikObjectClassifierModel diff --git a/imagej/infer_ilastik_by_api.py b/imagej/infer_ilastik_by_api.py index c4f0dda32b2929495835a93f64ec57e18f009c2e..4e0d58577328a8fb0bcb84f2e9f9d12c3da33e9c 100644 --- a/imagej/infer_ilastik_by_api.py +++ b/imagej/infer_ilastik_by_api.py @@ -17,7 +17,7 @@ input_filename = os.path.split(abspath)[-1] outpath = 'C:\\Users\\rhodes\\projects\\proj0015-model-server\\resources\\testdata' -def hit_endpoint(method, endpoint, params=None, verbose=False): +def hit_endpoint(method, endpoint, params=None, verbose=True): connection = httplib.HTTPConnection(host, port) if not method in ['GET', 'PUT']: raise Exception('Can only handle GET and PUT requests') @@ -32,9 +32,7 @@ def hit_endpoint(method, endpoint, params=None, verbose=False): print(method + ' ' + url + ', status ' + str(resp.status) + ':\n' + resp_str) return json.loads(resp_str) -#hit_endpoint('GET', '/') -#hit_endpoint('GET', '/models') -#hit_endpoint('PUT', '/bounce_back', {'par1': 'ghij'}) +hit_endpoint('GET', '/restart') resp = hit_endpoint('PUT', '/models/ilastik/pixel_classification/load/', {'project_file': 'demo_px.ilp'}) pxmid = resp['model_id'] resp = hit_endpoint('GET', '/models', verbose=True) @@ -45,4 +43,14 @@ infer_params = { 'channel': 0 } -hit_endpoint('PUT', '/infer/from_image_file', infer_params) \ No newline at end of file +hit_endpoint('PUT', '/infer/from_image_file', infer_params) + +import time + +dt_arr = [] +for i in range(0, 10): + t0 = time() + time.sleep(0.1) + dt_arr.append(time() - t0) +print(dt_arr) +print('mean [s]': sum(dt_arr)/len(dt_arr)) diff --git a/simulate_automic.py b/simulate_automic.py new file mode 100644 index 0000000000000000000000000000000000000000..94e042c8b0596aeb5bbb7ae493b1569fec4aedf8 --- /dev/null +++ b/simulate_automic.py @@ -0,0 +1,55 @@ +from multiprocessing import Process +import os +import requests +import unittest + +import uvicorn + +import conf.server + +# run server in subprocess + +host = '127.0.0.1' +port = 5000 +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() + +# configure and validate folders etc. +paths = conf.server.paths +paths['automic_watch_folder'] = paths['images']['inbound'] +paths['test_source_files'] = '' + +# load models by API + +# prompt user start AutoMic loop + +# move files from one folder to another +def copy_one_input_image_files(copy=True): + pattern = '' + os.listdir(paths['test_source_files']) + + # order by increaseing alpha order? timestamp? + + + if copy: + # copy image from test source files to automic watch folder + else: + # move them + + # recursive repeat until nothign is left + +# point to server session logs + + +# shut down server +server_process.terminate() + + +# do something with the data? + diff --git a/tests/test_ilastik.py b/tests/test_ilastik.py index 204ad2375dab90ce2bffe57baab2c11625312163..2cb9b5cdecdc08659e7510a107be32b118d5e3e6 100644 --- a/tests/test_ilastik.py +++ b/tests/test_ilastik.py @@ -152,3 +152,21 @@ class TestIlastikOverApi(TestServerBaseClass): }, ) self.assertEqual(resp_infer.status_code, 200, resp_infer.content.decode()) + + def test_load_ilastik_pixel_model_in_subdirectory(self): + px_ilp = 'proj0011-exp0004/px3d.ilp' + pf = px_ilp + + resp_load = requests.put( + self.uri + 'models/ilastik/pixel_classification/load/', + params={'project_file': pf}, + ) + model_id = resp_load.json()['model_id'] + + self.assertEqual(resp_load.status_code, 200, resp_load.json()) + resp_list = requests.get(self.uri + 'models') + self.assertEqual(resp_list.status_code, 200) + rj = resp_list.json() + self.assertEqual(rj[model_id]['class'], 'IlastikPixelClassifierModel') + + return model_id