Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tfscripts/compat/v1/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def pool3d(layer, ksize, strides, padding, pooling_type):
The pooled output tensor.
"""

# tensorflow's pooling operations do not support float64, so
# use workaround with casting to float32 and then back again
if layer.dtype == tf.float64:
layer = tf.cast(layer, tf.float32)
was_float64 = True
else:
was_float64 = False

# pool over depth, if necessary:
if ksize[-1] != 1 or strides[-1] != 1:
layer = pool_over_depth(layer,
Expand Down Expand Up @@ -70,6 +78,9 @@ def pool3d(layer, ksize, strides, padding, pooling_type):
padding=padding)
layer = (layer_avg + layer_max) / 2.

if was_float64:
layer = tf.cast(layer, tf.float64)

return layer


Expand Down Expand Up @@ -97,6 +108,14 @@ def pool(layer, ksize, strides, padding, pooling_type):
The pooled output tensor.
"""

# tensorflow's pooling operations do not support float64, so
# use workaround with casting to float32 and then back again
if layer.dtype == tf.float64:
layer = tf.cast(layer, tf.float32)
was_float64 = True
else:
was_float64 = False

# pool over depth, if necessary:
if ksize[-1] != 1 or strides[-1] != 1:
layer = pool_over_depth(layer,
Expand Down Expand Up @@ -138,6 +157,10 @@ def pool(layer, ksize, strides, padding, pooling_type):
padding=padding,
)
layer = (layer_avg + layer_max) / 2.

if was_float64:
layer = tf.cast(layer, tf.float64)

return layer


Expand Down
23 changes: 23 additions & 0 deletions tfscripts/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def pool3d(layer, ksize, strides, padding, pooling_type):
The pooled output tensor.
"""

# tensorflow's pooling operations do not support float64, so
# use workaround with casting to float32 and then back again
if layer.dtype == tf.float64:
layer = tf.cast(layer, tf.float32)
was_float64 = True
else:
was_float64 = False

# pool over depth, if necessary:
if ksize[-1] != 1 or strides[-1] != 1:
layer = pool_over_depth(layer,
Expand Down Expand Up @@ -70,6 +78,9 @@ def pool3d(layer, ksize, strides, padding, pooling_type):
padding=padding)
layer = (layer_avg + layer_max) / 2.

if was_float64:
layer = tf.cast(layer, tf.float64)

return layer


Expand Down Expand Up @@ -97,6 +108,14 @@ def pool2d(layer, ksize, strides, padding, pooling_type):
The pooled output tensor.
"""

# tensorflow's pooling operations do not support float64, so
# use workaround with casting to float32 and then back again
if layer.dtype == tf.float64:
layer = tf.cast(layer, tf.float32)
was_float64 = True
else:
was_float64 = False

# pool over depth, if necessary:
if ksize[-1] != 1 or strides[-1] != 1:
layer = pool_over_depth(layer,
Expand Down Expand Up @@ -130,6 +149,10 @@ def pool2d(layer, ksize, strides, padding, pooling_type):
strides=strides,
padding=padding)
layer = (layer_avg + layer_max) / 2.

if was_float64:
layer = tf.cast(layer, tf.float64)

return layer


Expand Down