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

Function get_padding_shape

python/singa/utils.py:159–186  ·  view source on GitHub ↗

return padding shape of conv2d or pooling, Args: pad_mode: string kernel_spatial_shape: list[int] strides_spatial: list[int] Returns: list[int]

(pad_mode, input_spatial_shape, kernel_spatial_shape,
                      strides_spatial)

Source from the content-addressed store, hash-verified

157
158
159def get_padding_shape(pad_mode, input_spatial_shape, kernel_spatial_shape,
160 strides_spatial):
161 """
162 return padding shape of conv2d or pooling,
163 Args:
164 pad_mode: string
165 kernel_spatial_shape: list[int]
166 strides_spatial: list[int]
167 Returns:
168 list[int]
169 """
170 output_spatial_shape = get_output_shape(pad_mode, input_spatial_shape,
171 kernel_spatial_shape,
172 strides_spatial)
173 pad_shape = [0] * len(input_spatial_shape) * 2 # 2 means left and right
174 # the odd paddding is the value that cannot be handled by the tuple padding (w, h) mode
175 # so we need to firstly handle the input, then use the nomal padding method.
176 odd_padd_shape = [0] * len(input_spatial_shape) * 2
177 for i in range(len(input_spatial_shape)):
178 whole_pad = (output_spatial_shape[i] - 1) * strides_spatial[i] + \
179 kernel_spatial_shape[i] - input_spatial_shape[i]
180 pad_shape[2 * i] = pad_shape[2 * i + 1] = whole_pad // 2
181 if whole_pad % 2 != 0:
182 if pad_mode == "SAME_UPPER":
183 odd_padd_shape[2 * i + 1] += 1
184 else:
185 odd_padd_shape[2 * i] += 1
186 return pad_shape, odd_padd_shape
187
188
189def get_output_shape(auto_pad, input_spatial_shape, kernel_spatial_shape,

Callers 1

same_pad_shape_checkFunction · 0.85

Calls 1

get_output_shapeFunction · 0.85

Tested by

no test coverage detected