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

Function spatial_2d_padding

tensorflow/python/keras/backend.py:3001–3028  ·  view source on GitHub ↗

Pads the 2nd and 3rd dimensions of a 4D tensor. Arguments: x: Tensor or variable. padding: Tuple of 2 tuples, padding pattern. data_format: One of `channels_last` or `channels_first`. Returns: A padded 4D tensor. Raises: ValueError: if `data_format` is neither

(x, padding=((1, 1), (1, 1)), data_format=None)

Source from the content-addressed store, hash-verified

2999
3000@keras_export('keras.backend.spatial_2d_padding')
3001def spatial_2d_padding(x, padding=((1, 1), (1, 1)), data_format=None):
3002 """Pads the 2nd and 3rd dimensions of a 4D tensor.
3003
3004 Arguments:
3005 x: Tensor or variable.
3006 padding: Tuple of 2 tuples, padding pattern.
3007 data_format: One of `channels_last` or `channels_first`.
3008
3009 Returns:
3010 A padded 4D tensor.
3011
3012 Raises:
3013 ValueError: if `data_format` is neither
3014 `channels_last` or `channels_first`.
3015 """
3016 assert len(padding) == 2
3017 assert len(padding[0]) == 2
3018 assert len(padding[1]) == 2
3019 if data_format is None:
3020 data_format = image_data_format()
3021 if data_format not in {'channels_first', 'channels_last'}:
3022 raise ValueError('Unknown data_format: ' + str(data_format))
3023
3024 if data_format == 'channels_first':
3025 pattern = [[0, 0], [0, 0], list(padding[0]), list(padding[1])]
3026 else:
3027 pattern = [[0, 0], list(padding[0]), list(padding[1]), [0, 0]]
3028 return array_ops.pad(x, pattern)
3029
3030
3031@keras_export('keras.backend.spatial_3d_padding')

Callers

nothing calls this directly

Calls 1

image_data_formatFunction · 0.85

Tested by

no test coverage detected