MCPcopy Create free account
hub / github.com/apache/singa / same_pad_shape_check

Function same_pad_shape_check

python/singa/utils.py:110–129  ·  view source on GitHub ↗

check the shape is correct for same padding mode Args: handle, the handle pad_mode, pad_mode x: input tensor Returns: tuple, the correct padding(before divide 2)

(handle, pad_mode, x)

Source from the content-addressed store, hash-verified

108
109
110def same_pad_shape_check(handle, pad_mode, x):
111 """
112 check the shape is correct for same padding mode
113 Args:
114 handle, the handle
115 pad_mode, pad_mode
116 x: input tensor
117 Returns:
118 tuple, the correct padding(before divide 2)
119 """
120 _kernel = [handle.kernel_h, handle.kernel_w]
121 _stride = [handle.stride_h, handle.stride_w]
122 _padding = [handle.pad_h, handle.pad_w]
123 _padding_correct = get_padding_shape(pad_mode,
124 x.shape()[2:], _kernel, _stride)
125 _padding_crop, _ = [x // 2 for x in _padding_correct]
126 assert _padding == _padding_crop, (
127 'For a same mode, the given padding %s is wrong, the correct one should be %s.'
128 % (_padding, _padding_crop))
129 return _padding_correct
130
131
132def re_new_handle(handle, x, is_pool=False):

Callers

nothing calls this directly

Calls 2

get_padding_shapeFunction · 0.85
shapeMethod · 0.80

Tested by

no test coverage detected