Extract the spatial parameters that determine the coordinate mapping: kernel size, stride, padding, and dilation. Implementation detail: Convolution, Deconvolution, and Im2col layers define these in the convolution_param message, while Pooling has its own fields in pooling_para
(fn)
| 16 | |
| 17 | |
| 18 | def conv_params(fn): |
| 19 | """ |
| 20 | Extract the spatial parameters that determine the coordinate mapping: |
| 21 | kernel size, stride, padding, and dilation. |
| 22 | |
| 23 | Implementation detail: Convolution, Deconvolution, and Im2col layers |
| 24 | define these in the convolution_param message, while Pooling has its |
| 25 | own fields in pooling_param. This method deals with these details to |
| 26 | extract canonical parameters. |
| 27 | """ |
| 28 | params = fn.params.get('convolution_param', fn.params) |
| 29 | axis = params.get('axis', 1) |
| 30 | ks = np.array(params['kernel_size'], ndmin=1) |
| 31 | dilation = np.array(params.get('dilation', 1), ndmin=1) |
| 32 | assert len({'pad_h', 'pad_w', 'kernel_h', 'kernel_w', 'stride_h', |
| 33 | 'stride_w'} & set(fn.params)) == 0, \ |
| 34 | 'cropping does not support legacy _h/_w params' |
| 35 | return (axis, np.array(params.get('stride', 1), ndmin=1), |
| 36 | (ks - 1) * dilation + 1, |
| 37 | np.array(params.get('pad', 0), ndmin=1)) |
| 38 | |
| 39 | |
| 40 | def crop_params(fn): |