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

Function convolution_internal

tensorflow/python/ops/nn_ops.py:965–1049  ·  view source on GitHub ↗

Internal function which performs rank agnostic convolution.

(
    input,  # pylint: disable=redefined-builtin
    filters,
    strides=None,
    padding="VALID",
    data_format=None,
    dilations=None,
    name=None,
    call_from_convolution=True)

Source from the content-addressed store, hash-verified

963
964
965def convolution_internal(
966 input, # pylint: disable=redefined-builtin
967 filters,
968 strides=None,
969 padding="VALID",
970 data_format=None,
971 dilations=None,
972 name=None,
973 call_from_convolution=True):
974 """Internal function which performs rank agnostic convolution."""
975 if isinstance(input.shape, tensor_shape.TensorShape) and \
976 input.shape.rank is not None:
977 n = len(input.shape) - 2
978 elif not isinstance(input.shape, tensor_shape.TensorShape) and \
979 input.shape is not None:
980 n = len(input.shape) - 2
981 elif isinstance(filters.shape, tensor_shape.TensorShape) and \
982 filters.shape.rank is not None:
983 n = len(filters.shape) - 2
984 elif not isinstance(filters.shape, tensor_shape.TensorShape) and \
985 filters.shape is not None:
986 n = len(filters.shape) - 2
987 else:
988 raise ValueError("rank of input or filter must be known")
989
990 if not 1 <= n <= 3:
991 raise ValueError(
992 "Input tensor must be of rank 3, 4 or 5 but was {}.".format(n + 2))
993
994 if data_format is None:
995 channel_index = n + 1
996 else:
997 channel_index = 1 if data_format.startswith("NC") else n + 1
998
999 strides = _get_sequence(strides, n, channel_index, "strides")
1000 dilations = _get_sequence(dilations, n, channel_index, "dilations")
1001
1002 # copybara:strip_begin
1003 # TODO(b/138808492): Remove code inside copybara
1004 # to make TPU code and CPU code consistent.
1005 scopes = {1: "conv1d", 2: "Conv2D", 3: "Conv3D"}
1006 if not call_from_convolution and _enclosing_tpu_context() is not None:
1007 scope = scopes[n]
1008 else:
1009 scope = "convolution"
1010 # copybara:strip_end
1011 # copybara:insert scope = "convolution"
1012
1013 with ops.name_scope(name, scope, [input, filters]) as name:
1014 conv_ops = {1: conv1d, 2: gen_nn_ops.conv2d, 3: gen_nn_ops.conv3d}
1015
1016 # copybara:strip_begin
1017 # TODO(b/138808492): Remove code inside copybara
1018 # to make TPU code and CPU code consistent.
1019 if _enclosing_tpu_context() is not None or all(i == 1 for i in dilations):
1020 # fast path for TPU or if no dilation as gradient only supported on GPU
1021 # for dilations
1022 # copybara:strip_end

Callers 3

convolutionFunction · 0.85
convolution_v2Function · 0.85
__call__Method · 0.85

Calls 7

allFunction · 0.85
_get_sequenceFunction · 0.70
_enclosing_tpu_contextFunction · 0.70
opFunction · 0.70
ConvolutionClass · 0.70
formatMethod · 0.45
name_scopeMethod · 0.45

Tested by

no test coverage detected