Skip to content

Commit

Permalink
convert test_session to cached_session to avoid deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
willgraf committed Aug 9, 2019
1 parent e208fa0 commit 2341497
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 28 deletions.
6 changes: 3 additions & 3 deletions deepcell/layers/filter_detections_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestFilterDetections(test.TestCase):

@tf_test_util.run_in_graph_and_eager_modes()
def test_simple(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
# create simple FilterDetections layer
layer = layers.FilterDetections()

Expand Down Expand Up @@ -81,7 +81,7 @@ def test_simple(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_simple_with_other(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
# create simple FilterDetections layer
layer = layers.FilterDetections()

Expand Down Expand Up @@ -142,7 +142,7 @@ def test_simple_with_other(self):

# @tf_test_util.run_in_graph_and_eager_modes()
# def test_mini_batch(self):
# with self.test_session(use_gpu=True):
# with self.cached_session(use_gpu=True):
# # create simple FilterDetections layer
# layer = layers.FilterDetections()
#
Expand Down
4 changes: 2 additions & 2 deletions deepcell/layers/location_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LocationTest(test.TestCase):

@tf_test_util.run_in_graph_and_eager_modes()
def test_location_2d(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.Location2D,
kwargs={'in_shape': (5, 6, 4),
Expand All @@ -55,7 +55,7 @@ def test_location_2d(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_location_3d(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.Location3D,
kwargs={'in_shape': (11, 12, 10, 4),
Expand Down
4 changes: 2 additions & 2 deletions deepcell/layers/normalization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ImageNormalizationTest(test.TestCase):
def test_normalize_2d(self):
custom_objects = {'ImageNormalization2D': layers.ImageNormalization2D}
norm_methods = [None, 'std', 'max', 'whole_image']
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
# test each norm method
for norm_method in norm_methods:
testing_utils.layer_test(
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_normalize_2d(self):
def test_normalize_3d(self):
custom_objects = {'ImageNormalization3D': layers.ImageNormalization3D}
norm_methods = [None, 'std', 'max', 'whole_image']
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
# test each norm method
for norm_method in norm_methods:
testing_utils.layer_test(
Expand Down
8 changes: 4 additions & 4 deletions deepcell/layers/padding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_reflection_padding_2d(self):
data_formats = ['channels_first', 'channels_last']
for data_format, inputs in zip(data_formats, [ins2, ins1]):
# basic test
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.ReflectionPadding2D,
kwargs={'padding': (2, 2),
Expand All @@ -75,7 +75,7 @@ def test_reflection_padding_2d(self):
input_shape=inputs.shape)

# correctness test
# with self.test_session(use_gpu=True):
# with self.cached_session(use_gpu=True):
# layer = layers.ReflectionPadding2D(
# padding=(2, 2), data_format=data_format)
# layer.build(inputs.shape)
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_reflection_padding_3d(self):
data_formats = ['channels_first', 'channels_last']
for data_format, inputs in zip(data_formats, [inputs2, inputs1]):
# basic test
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.ReflectionPadding3D,
kwargs={'padding': (2, 2, 2),
Expand All @@ -155,7 +155,7 @@ def test_reflection_padding_3d(self):
input_shape=inputs.shape)

# correctness test
# with self.test_session(use_gpu=True):
# with self.cached_session(use_gpu=True):
# layer = layers.ReflectionPadding3D(padding=(2, 2, 2))
# layer.build(inputs.shape)
# output = layer(keras.backend.variable(inputs))
Expand Down
4 changes: 2 additions & 2 deletions deepcell/layers/pooling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_dilated_max_pool_2d(self):
for strides in [(1, 1), (2, 2), None]:
for dilation_rate in [1, 2]:
for padding in ['valid', 'same']:
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.DilatedMaxPool2D,
kwargs={'strides': strides,
Expand All @@ -71,7 +71,7 @@ def test_dilated_max_pool_3d(self):
for strides in [1, 2, None]:
for dilation_rate in [1, 2]:
for padding in ['valid', 'same']:
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.DilatedMaxPool3D,
kwargs={'strides': strides,
Expand Down
2 changes: 1 addition & 1 deletion deepcell/layers/resize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ResizeTest(test.TestCase):

@tf_test_util.run_in_graph_and_eager_modes()
def test_resize_2d(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.Resize2D,
kwargs={'scale': 2},
Expand Down
14 changes: 7 additions & 7 deletions deepcell/layers/retinanet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestAnchors(test.TestCase):

@tf_test_util.run_in_graph_and_eager_modes()
def test_anchors_2d(self):
with self.test_session(use_gpu=True):
with self.cached_session(use_gpu=True):
testing_utils.layer_test(
layers.Anchors,
kwargs={'size': 1, 'stride': 1,
Expand All @@ -63,7 +63,7 @@ def test_anchors_2d(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_simple(self):
with self.test_session():
with self.cached_session():
# create simple Anchors layer
anchors_layer = layers.Anchors(
size=32,
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_simple(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_mini_batch(self):
with self.test_session():
with self.cached_session():
# create simple Anchors layer
anchors_layer = layers.Anchors(
size=32,
Expand Down Expand Up @@ -127,7 +127,7 @@ class TestRegressBoxes(test.TestCase):

@tf_test_util.run_in_graph_and_eager_modes()
def test_simple(self):
with self.test_session():
with self.cached_session():
# create simple RegressBoxes layer
layer = layers.RegressBoxes()

Expand Down Expand Up @@ -165,7 +165,7 @@ def test_simple(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_mini_batch(self):
with self.test_session():
with self.cached_session():
mean = [0, 0, 0, 0]
std = [0.2, 0.2, 0.2, 0.2]

Expand Down Expand Up @@ -257,7 +257,7 @@ def test_simple(self):
]], dtype=K.floatx())

# test channels_last
with self.test_session():
with self.cached_session():
# create input
image = K.variable(np.random.random((1, img_h, img_w, 3)))

Expand All @@ -274,7 +274,7 @@ def test_simple(self):
self.assertAllClose(actual, expected)

# test channels_first
with self.test_session():
with self.cached_session():
# create input
image = K.variable(np.random.random((1, 6, img_h, img_w)))

Expand Down
4 changes: 2 additions & 2 deletions deepcell/layers/tensor_product_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_tensorproduct(self):
input_shape=(3, 5, 6, None))

def test_tensorproduct_regularization(self):
with self.test_session():
with self.cached_session():
layer = layers.TensorProduct(
3,
kernel_regularizer=keras.regularizers.l1(0.01),
Expand All @@ -103,7 +103,7 @@ def test_tensorproduct_regularization(self):
self.assertEqual(3, len(layer.losses))

def test_tensorproduct_constraints(self):
with self.test_session():
with self.cached_session():
k_constraint = keras.constraints.max_norm(0.01)
b_constraint = keras.constraints.max_norm(0.01)
layer = layers.TensorProduct(
Expand Down
6 changes: 3 additions & 3 deletions deepcell/layers/upsample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestUpsampleLike(test.TestCase):
@tf_test_util.run_in_graph_and_eager_modes()
def test_simple(self):
# channels_last
with self.test_session():
with self.cached_session():
# create simple UpsampleLike layer
upsample_like_layer = layers.UpsampleLike()

Expand All @@ -63,7 +63,7 @@ def test_simple(self):
self.assertEqual(actual.shape, computed_shape)
self.assertAllEqual(actual, expected)
# channels_first
with self.test_session():
with self.cached_session():
# create simple UpsampleLike layer
upsample_like_layer = layers.UpsampleLike(
data_format='channels_first')
Expand All @@ -86,7 +86,7 @@ def test_simple(self):

@tf_test_util.run_in_graph_and_eager_modes()
def test_mini_batch(self):
with self.test_session():
with self.cached_session():
# create simple UpsampleLike layer
upsample_like_layer = layers.UpsampleLike()

Expand Down
15 changes: 13 additions & 2 deletions deepcell/model_zoo/featurenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,19 @@ def bn_feature_net_skip_2D(receptive_field=61,
else:
model_input = img

new_input_shape = model_input.get_shape().as_list()[1:]
models.append(bn_feature_net_2D(receptive_field=receptive_field, input_shape=new_input_shape, norm_method=None, dilated=True, padding=True, padding_mode=padding_mode, **kwargs))
_model_kwargs = {
'receptive_field': receptive_field,
'input_shape': model_input.get_shape().as_list()[1:],
'norm_method': None,
'dilated': True,
'padding': True,
'padding_mode': padding_mode,
}
for k in kwargs:
if k not in _model_kwargs:
_model_kwargs[k] = kwargs[k]

models.append(bn_feature_net_2D(**_model_kwargs))
model_outputs.append(models[-1](model_input))

if last_only:
Expand Down

0 comments on commit 2341497

Please sign in to comment.