Skip to content

Commit

Permalink
Merge 66ef232 into 0004df9
Browse files Browse the repository at this point in the history
  • Loading branch information
ngreenwald committed Aug 16, 2021
2 parents 0004df9 + 66ef232 commit 976b6e9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
50 changes: 27 additions & 23 deletions deepcell/applications/mesmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def predict(self,
preprocess_kwargs={},
compartment='whole-cell',
pad_mode='constant',
postprocess_kwargs_whole_cell=None,
postprocess_kwargs_nuclear=None):
postprocess_kwargs_whole_cell={},
postprocess_kwargs_nuclear={}):
"""Generates a labeled image of the input running prediction with
appropriate pre and post processing functions.
Expand Down Expand Up @@ -268,28 +268,32 @@ def predict(self,
Returns:
numpy.array: Instance segmentation mask.
"""
default_kwargs_cell = {
'maxima_threshold': 0.1,
'maxima_smooth': 0,
'interior_threshold': 0.3,
'interior_smooth': 2,
'small_objects_threshold': 15,
'fill_holes_threshold': 15,
'radius': 2
}

default_kwargs_nuc = {
'maxima_threshold': 0.1,
'maxima_smooth': 0,
'interior_threshold': 0.3,
'interior_smooth': 2,
'small_objects_threshold': 15,
'fill_holes_threshold': 15,
'radius': 2
}

# overwrite defaults with any user-provided values
postprocess_kwargs_whole_cell = {**default_kwargs_cell,
**postprocess_kwargs_whole_cell}

if postprocess_kwargs_whole_cell is None:
postprocess_kwargs_whole_cell = {
'maxima_threshold': 0.1,
'maxima_smooth': 0,
'interior_threshold': 0.3,
'interior_smooth': 2,
'small_objects_threshold': 15,
'fill_holes_threshold': 15,
'radius': 2
}

if postprocess_kwargs_nuclear is None:
postprocess_kwargs_nuclear = {
'maxima_threshold': 0.1,
'maxima_smooth': 0,
'interior_threshold': 0.3,
'interior_smooth': 2,
'small_objects_threshold': 15,
'fill_holes_threshold': 15,
'radius': 2
}
postprocess_kwargs_nuclear = {**default_kwargs_nuc,
**postprocess_kwargs_nuclear}

# create dict to hold all of the post-processing kwargs
postprocess_kwargs = {
Expand Down
34 changes: 34 additions & 0 deletions deepcell/applications/mesmer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import numpy as np

from unittest.mock import Mock

from tensorflow.python.platform import test

from deepcell.model_zoo import PanopticNet
Expand Down Expand Up @@ -222,6 +224,38 @@ def test_mesmer_app(self):
self.assertEqual(x.shape[:-1], y.shape[:-1])
self.assertEqual(y.shape[-1], 2)

# test that kwargs are passed through successfully
app._predict_segmentation = Mock()

# get defaults
_ = app.predict(x, compartment='whole-cell')
args = app._predict_segmentation.call_args[1]
default_cell_kwargs = args['postprocess_kwargs']['whole_cell_kwargs']
default_nuc_kwargs = args['postprocess_kwargs']['nuclear_kwargs']

# change one of the args for each compartment
maxima_threshold_cell = default_cell_kwargs['maxima_threshold'] + 0.1
radius_nuc = default_nuc_kwargs['radius'] + 2

_ = app.predict(x, compartment='whole-cell',
postprocess_kwargs_whole_cell={'maxima_threshold':
maxima_threshold_cell},
postprocess_kwargs_nuclear={'radius': radius_nuc})

args = app._predict_segmentation.call_args[1]
cell_kwargs = args['postprocess_kwargs']['whole_cell_kwargs']
assert cell_kwargs['maxima_threshold'] == maxima_threshold_cell

nuc_kwargs = args['postprocess_kwargs']['nuclear_kwargs']
assert nuc_kwargs['radius'] == radius_nuc

# check that rest are unchanged
cell_kwargs['maxima_threshold'] = default_cell_kwargs['maxima_threshold']
assert cell_kwargs == default_cell_kwargs

nuc_kwargs['radius'] = default_nuc_kwargs['radius']
assert nuc_kwargs == default_nuc_kwargs

# test legacy version
old_app = MultiplexSegmentation(model)

Expand Down

0 comments on commit 976b6e9

Please sign in to comment.