diff --git a/model_server/model.py b/model_server/model.py index 8c07d2d8c0d71dd3caa724905d2ea40566b865d8..38b772ffbfd569552401b913aec46bbef1b1c327 100644 --- a/model_server/model.py +++ b/model_server/model.py @@ -18,10 +18,12 @@ class Model(ABC): """ self.autoload = autoload self.params = params + self.loaded = False + if not autoload: + return None if self.load(): self.loaded = True else: - self.loaded = False raise CouldNotLoadModelError() return None diff --git a/model_server/session.py b/model_server/session.py index 8831b60696d1edaeb8501ac0fec93d9bd3a3d085..bd9a5d9d8955c5d3f25181d776927166d8bbab80 100644 --- a/model_server/session.py +++ b/model_server/session.py @@ -73,7 +73,7 @@ class Session(object): for mc in models: if hasattr(mc, 'model_id') and getattr(mc, 'model_id') == model_id: try: - mi = mc(params) + mi = mc(params=params) assert mi.loaded except: raise CouldNotInstantiateModelError() diff --git a/tests/test_api.py b/tests/test_api.py index f2805eefce92f5c404173da1e36649f3b57d4e18..0b2e844bdbea032a426191077036bb255aa14e93 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -93,5 +93,5 @@ class TestApiFromAutomatedClient(unittest.TestCase): 'channel': 2, }, ) - self.assertEqual(resp_infer.status_code, 200, f'Error inferring from {model_id}', resp_infer.content.decode()) + self.assertEqual(resp_infer.status_code, 200, resp_infer.content.decode()) diff --git a/tests/test_ilastik.py b/tests/test_ilastik.py index ac387a41b600ff5287d284d329fd9752d430b845..9a596bced7601aed55b4ecf9929a37fb90578617 100644 --- a/tests/test_ilastik.py +++ b/tests/test_ilastik.py @@ -21,6 +21,17 @@ class TestIlastikPixelClassification(unittest.TestCase): with self.assertRaises(io.UnsupportedOperation): faulthandler.enable(file=sys.stdout) + + def test_raise_error_if_autoload_disabled(self): + model = IlastikPixelClassifierModel({'project_file': ilastik['pixel_classifier']}, autoload=False) + w = 512 + h = 256 + + input_img = InMemoryDataAccessor(data=np.random.rand(w, h, 1, 1)) + + with self.assertRaises(AttributeError): + pxmap = model.infer(input_img) + def test_run_pixel_classifier_on_random_data(self): model = IlastikPixelClassifierModel({'project_file': ilastik['pixel_classifier']}) w = 512 @@ -47,7 +58,6 @@ class TestIlastikPixelClassification(unittest.TestCase): self.assertEqual(pxmap.shape[0:2], cf.shape[0:2]) self.assertEqual(pxmap.shape_dict['C'], 2) self.assertEqual(pxmap.shape_dict['Z'], 1) - print(pxmap.shape_dict) self.assertTrue( write_accessor_data_to_file( output_path / f'pxmap_{cf.fpath.stem}_ch{channel}.tif', diff --git a/tests/test_model.py b/tests/test_model.py index 9f4ab388190a651536ef29b86fc082f2978f9584..b2654af69b5eb725a220e3f60bc4226174c1165d 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -8,7 +8,7 @@ class TestCziImageFileAccess(unittest.TestCase): self.cf = CziImageFileAccessor(czifile['path']) def test_instantiate_model(self): - model = DummyImageToImageModel() + model = DummyImageToImageModel(params=None) self.assertTrue(model.loaded) def test_instantiate_model_with_nondefault_kwarg(self): diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 83935d3df306542cfbe0ea6f95efce591f28d5ea..6bc8d56d88f960d63cdada4efe68e65c6ecd572f 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -20,7 +20,7 @@ class TestGetSessionObject(unittest.TestCase): self.assertEqual( img.shape, - (h, w, 1, 1), + (h, w), 'Inferred image is not the expected shape' )