diff --git a/model_server/ilastik.py b/model_server/ilastik.py index aadfad6acbc63f411e549475cef286a91fe823ef..c7df35d450393ce835518392e0abf84b1f02bd14 100644 --- a/model_server/ilastik.py +++ b/model_server/ilastik.py @@ -71,7 +71,7 @@ class IlastikPixelClassifierModel(IlastikImageToImageModel): [2, 1, 3, 0], [0, 1, 2, 3] ) - return InMemoryDataAccessor(data=xycz) + return InMemoryDataAccessor(data=xycz), {'success': True} diff --git a/model_server/model.py b/model_server/model.py index 38b772ffbfd569552401b913aec46bbef1b1c327..7ee63af4e906683c6040b994a149472390ed704d 100644 --- a/model_server/model.py +++ b/model_server/model.py @@ -47,9 +47,8 @@ class Model(ABC): pass @abstractmethod - def infer(self, img: GenericImageDataAccessor) -> (np.ndarray, dict): # return json describing inference result - if self.autoload: - self.load() + def infer(self, img: GenericImageDataAccessor) -> (object, dict): # return json describing inference result + pass def reload(self): self.load() @@ -61,8 +60,8 @@ class ImageToImageModel(Model): """ @abstractmethod - def infer(self, img) -> (GenericImageDataAccessor, dict): - super().infer(img) + def infer(self, img: GenericImageDataAccessor) -> (GenericImageDataAccessor, dict): + pass class DummyImageToImageModel(ImageToImageModel): @@ -71,13 +70,13 @@ class DummyImageToImageModel(ImageToImageModel): def load(self): return True - def infer(self, img: GenericImageDataAccessor) -> GenericImageDataAccessor: + def infer(self, img: GenericImageDataAccessor) -> (GenericImageDataAccessor, dict): super().infer(img) w = img.shape_dict['X'] h = img.shape_dict['Y'] result = np.zeros([h, w], dtype='uint8') result[floor(0.25 * h) : floor(0.75 * h), floor(0.25 * w) : floor(0.75 * w)] = 255 - return InMemoryDataAccessor(data=result) + return InMemoryDataAccessor(data=result), {'success': True} class Error(Exception): pass diff --git a/model_server/workflow.py b/model_server/workflow.py index 38803ed6ea391240ae5641423e55e25d311dc07d..070cd25cc48b777a60651b11c7adaaa34d3dde57 100644 --- a/model_server/workflow.py +++ b/model_server/workflow.py @@ -28,7 +28,7 @@ def infer_image_to_image(fpi, model, where_output, **kwargs) -> dict: # run model inference # TODO: call this async / await and report out infer status to optional callback - outdata = model.infer(img) + outdata, _ = model.infer(img) dt_inf = time() - t0 # TODO: assert outdata format diff --git a/tests/test_ilastik.py b/tests/test_ilastik.py index 9a596bced7601aed55b4ecf9929a37fb90578617..19db57fa0d1c2098b6e426a156dd63165f1c4b57 100644 --- a/tests/test_ilastik.py +++ b/tests/test_ilastik.py @@ -30,7 +30,7 @@ class TestIlastikPixelClassification(unittest.TestCase): input_img = InMemoryDataAccessor(data=np.random.rand(w, h, 1, 1)) with self.assertRaises(AttributeError): - pxmap = model.infer(input_img) + pxmap , _= model.infer(input_img) def test_run_pixel_classifier_on_random_data(self): model = IlastikPixelClassifierModel({'project_file': ilastik['pixel_classifier']}) @@ -39,7 +39,7 @@ class TestIlastikPixelClassification(unittest.TestCase): input_img = InMemoryDataAccessor(data=np.random.rand(w, h, 1, 1)) - pxmap = model.infer(input_img) + pxmap, _ = model.infer(input_img) self.assertEqual(pxmap.shape, (w, h, 2, 1)) def test_run_pixel_classifier(self): @@ -53,7 +53,7 @@ class TestIlastikPixelClassification(unittest.TestCase): self.assertEqual(mono_image.shape_dict['C'], 1) self.assertEqual(mono_image.shape_dict['Z'], 1) - pxmap = model.infer(mono_image) + pxmap, _ = model.infer(mono_image) self.assertEqual(pxmap.shape[0:2], cf.shape[0:2]) self.assertEqual(pxmap.shape_dict['C'], 2) diff --git a/tests/test_model.py b/tests/test_model.py index b2654af69b5eb725a220e3f60bc4226174c1165d..911b9f7479bc2da3ff1aae045c824594118aa3f0 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -25,7 +25,7 @@ class TestCziImageFileAccess(unittest.TestCase): def test_czifile_is_correct_shape(self): model = DummyImageToImageModel() - img = model.infer(self.cf) + img, _ = model.infer(self.cf) w = czifile['w'] h = czifile['h']