def test_nuclear_app(self): with self.cached_session(): model = PanopticNet( 'resnet50', input_shape=(128, 128, 1), norm_method='whole_image', num_semantic_heads=2, num_semantic_classes=[1, 1], location=True, include_top=True, lite=True, use_imagenet=False, interpolation='bilinear') app = NuclearSegmentation(model) # test output shape shape = app.model.output_shape self.assertIsInstance(shape, list) self.assertEqual(len(shape), 2) self.assertEqual(len(shape[0]), 4) self.assertEqual(len(shape[1]), 4) # test predict x = np.random.rand(1, 500, 500, 1) y = app.predict(x) self.assertEqual(x.shape, y.shape)
def test_nuclear_app(self): with self.cached_session(): app = NuclearSegmentation(use_pretrained_weights=False) # test output shape shape = app.model.output_shape self.assertIsInstance(shape, list) self.assertEqual(len(shape), 2) self.assertEqual(len(shape[0]), 4) self.assertEqual(len(shape[1]), 4) # test predict x = np.random.rand(1, 500, 500, 1) y = app.predict(x) self.assertEqual(x.shape, y.shape)
def deepcell_segment(image: Array, compartment: str = None) -> Array: from deepcell.applications import ( MultiplexSegmentation, NuclearSegmentation, CytoplasmSegmentation, ) if compartment is None: # If image has more than one channel i.e. CYX # assume segmentation of both compartments, otherwise nuclear compartment = "both" if image.shape[-1] > 1 else "nuclear" if compartment == "nuclear": app = NuclearSegmentation() pred = app.predict(image).squeeze() if compartment == "cytoplasm": app = CytoplasmSegmentation() pred = app.predict(image).squeeze() if compartment == "both": app = MultiplexSegmentation() pred = app.predict(image, compartment=compartment).squeeze() if len(pred.shape) == 4: pred = resize(pred, image.shape[1:]) return pred
def deepcell_segmenter(self, input_img, cell_dia=None): from deepcell.applications import NuclearSegmentation app = NuclearSegmentation() im = np.expand_dims(input_img, axis=-1) im = np.expand_dims(im, axis=0) masks1 = app.predict(im, image_mpp=cell_dia) masks = np.squeeze(masks1) boundary = find_boundaries(masks, connectivity=1, mode='thick', background=0) boundary_img = (255 * boundary).astype('uint8') resized_bound = boundary_img filled1 = ndimage.binary_fill_holes(resized_bound) mask = (255 * filled1).astype('uint8') - resized_bound boundary = resized_bound.astype('uint8') return boundary, mask
class TestNuclearSegmentation(test.TestCase): def setUp(self): self.app = NuclearSegmentation(use_pretrained_weights=False) def test_nuclear_app(self): # Check shape parameters shape = self.app.model.output_shape self.assertIsInstance(shape, list) self.assertEqual(len(shape), 3) self.assertEqual(len(shape[0]), 4) self.assertEqual(len(shape[1]), 4) self.assertEqual(len(shape[2]), 4) def test_predict(self): x = np.random.rand(1, 500, 500, 1) y = self.app.predict(x) self.assertEqual(x.shape[:-1], y.shape)
def setUp(self): self.app = NuclearSegmentation(use_pretrained_weights=False)