Skip to content

Commit

Permalink
Merge 5d16cc4 into 406a931
Browse files Browse the repository at this point in the history
  • Loading branch information
willgraf committed Sep 29, 2020
2 parents 406a931 + 5d16cc4 commit ed93b08
Show file tree
Hide file tree
Showing 35 changed files with 6,428 additions and 921 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ git:
language: python

python:
- 3.6
# - 3.6
- 3.7

env:
- TF_VERSION=2.1.1
- TF_VERSION=2.2.0
- TF_VERSION=2.3.0

install:
# code below is taken from https://github.com/keras-team/keras/blob/master/.travis.yml
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Use tensorflow/tensorflow as the base image
# Change the build arg to edit the tensorflow version.
# Only supporting python3.
ARG TF_VERSION=2.1.0-gpu
ARG TF_VERSION=2.1.1-gpu

FROM tensorflow/tensorflow:${TF_VERSION}-py3
FROM tensorflow/tensorflow:${TF_VERSION}

# System maintenance
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/cell_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def CellTrackingModel(input_shape=(32, 32, 1),
'CellTrackingModel.h5',
WEIGHTS_PATH,
cache_subdir='models',
md5_hash='3349b363fdad0266a1845ba785e057a6')
file_hash='3349b363fdad0266a1845ba785e057a6')

model.load_weights(weights_path)

Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/cytoplasm_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self,
os.path.basename(WEIGHTS_PATH),
WEIGHTS_PATH,
cache_subdir='models',
md5_hash='104a7d7884c80c37d2bce6d1c3a17c7a'
file_hash='104a7d7884c80c37d2bce6d1c3a17c7a'
)

model.load_weights(weights_path, by_name=True)
Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/label_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def LabelDetectionModel(input_shape=(None, None, 1),
local_name,
MOBILENETV2_WEIGHTS_PATH,
cache_subdir='models',
md5_hash='14d4b2f7c77d334c958d2dde79972e6e')
file_hash='14d4b2f7c77d334c958d2dde79972e6e')
else:
raise ValueError('Backbone %s does not have a weights file.' %
backbone)
Expand Down
34 changes: 24 additions & 10 deletions deepcell/applications/multiplex_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@

from tensorflow.keras.utils import get_file

from deepcell_toolbox.deep_watershed import deep_watershed_subcellular, format_output_multiplex
from deepcell_toolbox.processing import phase_preprocess
from deepcell_toolbox.multiplex_utils import \
multiplex_preprocess, multiplex_postprocess, format_output_multiplex

from deepcell.applications import Application
from deepcell.model_zoo import PanopticNet


WEIGHTS_PATH = ('https://deepcell-data.s3-us-west-1.amazonaws.com/'
'model-weights/Multiplex_Segmentation_20200714_subcellular.h5')
'model-weights/Multiplex_Segmentation_20200908_2_head.h5')


class MultiplexSegmentation(Application):
Expand Down Expand Up @@ -109,8 +109,8 @@ def __init__(self,
use_pretrained_weights=True,
model_image_shape=(256, 256, 2)):

whole_cell_classes = [1, 1, 2, 3]
nuclear_classes = [1, 1, 2, 3]
whole_cell_classes = [1, 3]
nuclear_classes = [1, 3]
num_semantic_classes = whole_cell_classes + nuclear_classes
num_semantic_heads = len(num_semantic_classes)

Expand All @@ -128,7 +128,7 @@ def __init__(self,
os.path.basename(WEIGHTS_PATH),
WEIGHTS_PATH,
cache_subdir='models',
md5_hash='a2f26a7b5cc9a86d68e65a7bd27c32d0'
file_hash='4e440b0e329dd5c24c1162efa0a33bc9'
)

model.load_weights(weights_path)
Expand All @@ -138,8 +138,8 @@ def __init__(self,
super(MultiplexSegmentation, self).__init__(model,
model_image_shape=model_image_shape,
model_mpp=0.5,
preprocessing_fn=phase_preprocess,
postprocessing_fn=deep_watershed_subcellular,
preprocessing_fn=multiplex_preprocess,
postprocessing_fn=multiplex_postprocess,
format_model_output_fn=format_output_multiplex,
dataset_metadata=self.dataset_metadata,
model_metadata=self.model_metadata)
Expand All @@ -150,8 +150,8 @@ def predict(self,
image_mpp=None,
preprocess_kwargs={},
compartment='whole-cell',
postprocess_kwargs_whole_cell={},
postprocess_kwargs_nuclear={}):
postprocess_kwargs_whole_cell=None,
postprocess_kwargs_nuclear=None):
"""Generates a labeled image of the input running prediction with
appropriate pre and post processing functions.
Expand Down Expand Up @@ -182,6 +182,20 @@ def predict(self,
np.array: Model output
"""

if postprocess_kwargs_whole_cell is None:
postprocess_kwargs_whole_cell = {'maxima_threshold': 0.1, 'maxima_model_smooth': 0,
'interior_threshold': 0.3, 'interior_model_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_model_smooth': 0,
'interior_threshold': 0.3, 'interior_model_smooth': 2,
'small_objects_threshold': 15,
'fill_holes_threshold': 15,
'radius': 2}

# create dict to hold all of the post-processing kwargs
postprocess_kwargs = {'whole_cell_kwargs': postprocess_kwargs_whole_cell,
'nuclear_kwargs': postprocess_kwargs_nuclear,
Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/multiplex_segmentation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_multiplex_app(self):
# test output shape
shape = app.model.output_shape
self.assertIsInstance(shape, list)
self.assertEqual(len(shape), 8)
self.assertEqual(len(shape), 4)

# test predict with default
x = np.random.rand(1, 500, 500, 2)
Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/nuclear_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self,
os.path.basename(WEIGHTS_PATH),
WEIGHTS_PATH,
cache_subdir='models',
md5_hash='42ca0ebe4b7b0f782eaa4733cdddad88'
file_hash='42ca0ebe4b7b0f782eaa4733cdddad88'
)

model.load_weights(weights_path, by_name=True)
Expand Down
2 changes: 1 addition & 1 deletion deepcell/applications/scale_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def ScaleDetectionModel(input_shape=(None, None, 1),
local_name,
MOBILENETV2_WEIGHTS_PATH,
cache_subdir='models',
md5_hash='aa78e6b9a4551289dd967f1f5ca83fed')
file_hash='aa78e6b9a4551289dd967f1f5ca83fed')
else:
raise ValueError('Backbone %s does not have a weights file.' %
backbone)
Expand Down
8 changes: 8 additions & 0 deletions deepcell/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ def load_tracked_data(self, path=None, test_size=0.2, seed=0):
metadata={}
)

#:
multiplex_tissue = Dataset(
path='20200810_tissue_dataset.npz',
url='https://deepcell-data.s3.amazonaws.com/multiplex/20200810_tissue_dataset.npz',
file_hash='1e573b72123fd86e45433402094bf0d0',
metadata={}
)

# pylint: disable=wrong-import-position
from deepcell.datasets import cytoplasm
from deepcell.datasets import phase
Expand Down
42 changes: 28 additions & 14 deletions deepcell/image_generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@ def _transform_masks(y, transform, data_format=None, **kwargs):
'`outer-distance` transform instead.'.format(transform),
DeprecationWarning)

bins = kwargs.pop('distance_bins', None)
erosion = kwargs.pop('erosion_width', 0)
by_frame = kwargs.pop('by_frame', True)
bins = kwargs.pop('distance_bins', None)

distance_kwargs = {
'bins': bins,
'erosion_width': kwargs.pop('erosion_width', 0),
}

# If using 3d transform, pass in scale arg
if y.ndim == 5 and not by_frame:
distance_kwargs['sampling'] = kwargs.pop('sampling', [0.5, 0.217, 0.217])

if data_format == 'channels_first':
y_transform = np.zeros(tuple([y.shape[0]] + list(y.shape[2:])))
Expand All @@ -146,9 +154,7 @@ def _transform_masks(y, transform, data_format=None, **kwargs):
mask = y[batch, 0, ...]
else:
mask = y[batch, ..., 0]

y_transform[batch] = _distance_transform(
mask, bins=bins, erosion_width=erosion)
y_transform[batch] = _distance_transform(mask, **distance_kwargs)

y_transform = np.expand_dims(y_transform, axis=-1)

Expand All @@ -166,11 +172,19 @@ def _transform_masks(y, transform, data_format=None, **kwargs):
'`inner-distance` transform instead.'.format(transform),
DeprecationWarning)

bins = kwargs.pop('distance_bins', None)
erosion = kwargs.pop('erosion_width', 0)
by_frame = kwargs.pop('by_frame', True)
alpha = kwargs.pop('alpha', 0.1)
beta = kwargs.pop('beta', 1)
bins = kwargs.pop('distance_bins', None)

distance_kwargs = {
'bins': bins,
'erosion_width': kwargs.pop('erosion_width', 0),
'alpha': kwargs.pop('alpha', 0.1),
'beta': kwargs.pop('beta', 1)
}

# If using 3d transform, pass in scale arg
if y.ndim == 5 and not by_frame:
distance_kwargs['sampling'] = kwargs.pop('sampling', [0.5, 0.217, 0.217])

if data_format == 'channels_first':
y_transform = np.zeros(tuple([y.shape[0]] + list(y.shape[2:])))
Expand All @@ -190,14 +204,11 @@ def _transform_masks(y, transform, data_format=None, **kwargs):
mask = y[batch, 0, ...]
else:
mask = y[batch, ..., 0]

y_transform[batch] = _distance_transform(mask, bins=bins,
erosion_width=erosion,
alpha=alpha, beta=beta)
y_transform[batch] = _distance_transform(mask, **distance_kwargs)

y_transform = np.expand_dims(y_transform, axis=-1)

if bins is None:
if distance_kwargs['bins'] is None:
pass
else:
# convert to one hot notation
Expand Down Expand Up @@ -244,6 +255,9 @@ def _transform_masks(y, transform, data_format=None, **kwargs):
from deepcell.image_generators.semantic import SemanticMovieGenerator
from deepcell.image_generators.semantic import SemanticMovieIterator

from deepcell.image_generators.semantic import Semantic3DGenerator
from deepcell.image_generators.semantic import Semantic3DIterator

from deepcell.image_generators.sample import SampleDataGenerator
from deepcell.image_generators.sample import ImageSampleArrayIterator
from deepcell.image_generators.sample import SampleMovieDataGenerator
Expand Down

0 comments on commit ed93b08

Please sign in to comment.