Skip to content
Snippets Groups Projects
test_model.py 1.84 KiB
Newer Older
import unittest
from conf.testing import czifile
from base.accessors import CziImageFileAccessor
from base.models import DummySemanticSegmentationModel, DummyInstanceSegmentationModel, CouldNotLoadModelError

class TestCziImageFileAccess(unittest.TestCase):
    def setUp(self) -> None:
        self.cf = CziImageFileAccessor(czifile['path'])
    def test_instantiate_model(self):
        model = DummySemanticSegmentationModel(params=None)
    def test_instantiate_model_with_nondefault_kwarg(self):
        model = DummySemanticSegmentationModel(autoload=False)
        self.assertFalse(model.autoload, 'Could not override autoload flag in subclass of Model.')

    def test_raise_error_if_cannot_load_model(self):
        class UnloadableDummyImageToImageModel(DummySemanticSegmentationModel):
        with self.assertRaises(CouldNotLoadModelError):
            mi = UnloadableDummyImageToImageModel()
    def test_dummy_pixel_segmentation(self):
        model = DummySemanticSegmentationModel()
        img = self.cf.get_mono(0)
        mask = model.label_pixel_class(img)
            'Inferred image is not the expected shape'
        )

        self.assertEqual(
            mask.data[int(w/2), int(h/2)],
            255,
            'Middle pixel is not white as expected'
        )

        self.assertEqual(
        )
        return img, mask

    def test_dummy_instance_segmentation(self):
        img, mask = self.test_dummy_pixel_segmentation()
        model = DummyInstanceSegmentationModel()
        obmap = model.label_instance_class(img, mask)