MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _get_strides_and_dilation_rate

Function _get_strides_and_dilation_rate

tensorflow/python/ops/nn_ops.py:744–784  ·  view source on GitHub ↗

Helper function for verifying strides and dilation_rate arguments. This is used by `convolution` and `pool`. Args: num_spatial_dims: int strides: Optional. List of N ints >= 1. Defaults to [1]*N. If any value of strides is > 1, then all values of dilation_rate must be 1. d

(num_spatial_dims, strides, dilation_rate)

Source from the content-addressed store, hash-verified

742
743
744def _get_strides_and_dilation_rate(num_spatial_dims, strides, dilation_rate):
745 """Helper function for verifying strides and dilation_rate arguments.
746
747 This is used by `convolution` and `pool`.
748
749 Args:
750 num_spatial_dims: int
751 strides: Optional. List of N ints >= 1. Defaults to [1]*N. If any value
752 of strides is > 1, then all values of dilation_rate must be 1.
753 dilation_rate: Optional. List of N ints >= 1. Defaults to [1]*N. If any
754 value of dilation_rate is > 1, then all values of strides must be 1.
755
756 Returns:
757 Normalized (strides, dilation_rate) as int32 numpy arrays of shape
758 [num_spatial_dims].
759
760 Raises:
761 ValueError: if the parameters are invalid.
762 """
763 if dilation_rate is None:
764 dilation_rate = [1] * num_spatial_dims
765 elif len(dilation_rate) != num_spatial_dims:
766 raise ValueError("len(dilation_rate)=%d but should be %d" %
767 (len(dilation_rate), num_spatial_dims))
768 dilation_rate = np.array(dilation_rate, dtype=np.int32)
769 if np.any(dilation_rate < 1):
770 raise ValueError("all values of dilation_rate must be positive")
771
772 if strides is None:
773 strides = [1] * num_spatial_dims
774 elif len(strides) != num_spatial_dims:
775 raise ValueError("len(strides)=%d but should be %d" % (len(strides),
776 num_spatial_dims))
777 strides = np.array(strides, dtype=np.int32)
778 if np.any(strides < 1):
779 raise ValueError("all values of strides must be positive")
780
781 if np.any(strides > 1) and np.any(dilation_rate > 1):
782 raise ValueError(
783 "strides > 1 not supported in conjunction with dilation_rate > 1")
784 return strides, dilation_rate
785
786
787@tf_export(v1=["nn.convolution"])

Callers 2

__init__Method · 0.85
poolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected