Skip to content

Commit

Permalink
Merge 960cce0 into d4ac3b0
Browse files Browse the repository at this point in the history
  • Loading branch information
willgraf committed Jan 25, 2021
2 parents d4ac3b0 + 960cce0 commit 2898b74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions deepcell/applications/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ def _preprocess(self, image, **kwargs):

return image

def _tile_input(self, image):
def _tile_input(self, image, pad_mode='constant'):
"""Tile the input image to match shape expected by model
using the ``deepcell_toolbox`` function.
Only supports 4D images.
Args:
image (numpy.array): Input image to tile
pad_mode (str): The padding mode, one of "constant" or "reflect".
Raises:
ValueError: Input images must have only 4 dimensions
Expand Down Expand Up @@ -178,7 +179,8 @@ def _tile_input(self, image):
# Otherwise tile images larger than model size
else:
# Tile images, needs 4d
tiles, tiles_info = tile_image(image, model_input_shape=self.model_image_shape)
tiles, tiles_info = tile_image(image, model_input_shape=self.model_image_shape,
stride_ratio=0.75, pad_mode=pad_mode)

return tiles, tiles_info

Expand Down Expand Up @@ -296,12 +298,14 @@ def _resize_output(self, image, original_shape):
def _run_model(self,
image,
batch_size=4,
pad_mode='constant',
preprocess_kwargs={}):
"""Run the model to generate output probabilities on the data.
Args:
image (numpy.array): Image with shape ``[batch, x, y, channel]``
batch_size (int): Number of images to predict on per batch.
pad_mode (str): The padding mode, one of "constant" or "reflect".
preprocess_kwargs (dict): Keyword arguments to pass to
the preprocessing function.
Expand All @@ -313,7 +317,7 @@ def _run_model(self,
image = self._preprocess(image, **preprocess_kwargs)

# Tile images, raises error if the image is not 4d
tiles, tiles_info = self._tile_input(image)
tiles, tiles_info = self._tile_input(image, pad_mode=pad_mode)

# Run images through model
output_tiles = self.model.predict(tiles, batch_size=batch_size)
Expand All @@ -330,6 +334,7 @@ def _predict_segmentation(self,
image,
batch_size=4,
image_mpp=None,
pad_mode='constant',
preprocess_kwargs={},
postprocess_kwargs={}):
"""Generates a labeled image of the input running prediction with
Expand All @@ -344,6 +349,7 @@ def _predict_segmentation(self,
``[batch, x, y, channel]``.
batch_size (int): Number of images to predict on per batch.
image_mpp (float): Microns per pixel for ``image``.
pad_mode (str): The padding mode, one of "constant" or "reflect".
preprocess_kwargs (dict): Keyword arguments to pass to the
pre-processing function.
postprocess_kwargs (dict): Keyword arguments to pass to the
Expand Down Expand Up @@ -374,8 +380,10 @@ def _predict_segmentation(self,
resized_image = self._resize_input(image, image_mpp)

# Generate model outputs
output_images = self._run_model(image=resized_image, batch_size=batch_size,
preprocess_kwargs=preprocess_kwargs)
output_images = self._run_model(
image=resized_image, batch_size=batch_size,
pad_mode=pad_mode, preprocess_kwargs=preprocess_kwargs
)

# Postprocess predictions to create label image
label_image = self._postprocess(output_images, **postprocess_kwargs)
Expand Down
3 changes: 3 additions & 0 deletions deepcell/applications/nuclear_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def predict(self,
image,
batch_size=4,
image_mpp=None,
pad_mode='reflect',
preprocess_kwargs=None,
postprocess_kwargs=None):
"""Generates a labeled image of the input running prediction with
Expand All @@ -131,6 +132,7 @@ def predict(self,
``[batch, x, y, channel]``.
batch_size (int): Number of images to predict on per batch.
image_mpp (float): Microns per pixel for ``image``.
pad_mode (str): The padding mode, one of "constant" or "reflect".
preprocess_kwargs (dict): Keyword arguments to pass to the
pre-processing function.
postprocess_kwargs (dict): Keyword arguments to pass to the
Expand Down Expand Up @@ -164,5 +166,6 @@ def predict(self,
image,
batch_size=batch_size,
image_mpp=image_mpp,
pad_mode=pad_mode,
preprocess_kwargs=preprocess_kwargs,
postprocess_kwargs=postprocess_kwargs)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ tensorflow==2.3.1
jupyter>=1.0.0,<2
opencv-python-headless<=3.4.9.31
deepcell-tracking>=0.2.7
deepcell-toolbox>=0.8.3
deepcell-toolbox>=0.8.4

0 comments on commit 2898b74

Please sign in to comment.