Convolution operator in NCHW layout. Parameters ---------- a_np : numpy.ndarray 4-D with shape [batch, in_channel, in_height, in_width] w_np : numpy.ndarray 4-D with shape [num_filter, in_channel // groups, filter_height, filter_width] stride : int or a list/tu
(a_np, w_np, stride, padding, groups=1)
| 123 | |
| 124 | |
| 125 | def conv2d_nchw_python(a_np, w_np, stride, padding, groups=1): |
| 126 | """Convolution operator in NCHW layout. |
| 127 | |
| 128 | Parameters |
| 129 | ---------- |
| 130 | a_np : numpy.ndarray |
| 131 | 4-D with shape [batch, in_channel, in_height, in_width] |
| 132 | |
| 133 | w_np : numpy.ndarray |
| 134 | 4-D with shape [num_filter, in_channel // groups, filter_height, filter_width] |
| 135 | |
| 136 | stride : int or a list/tuple of two ints |
| 137 | Stride size, or [stride_height, stride_width] |
| 138 | |
| 139 | padding : int or str or a list/tuple of 2 or 4 ints |
| 140 | Padding size, or ['VALID', 'SAME'], or |
| 141 | [pad_height, pad_width] for 2 ints, or |
| 142 | [pad_top, pad_left, pad_bottom, pad_right] for 2 ints |
| 143 | |
| 144 | groups : int |
| 145 | Number of groups |
| 146 | |
| 147 | Returns |
| 148 | ------- |
| 149 | b_np : np.ndarray |
| 150 | 4-D with shape [batch, out_channel, out_height, out_width] |
| 151 | """ |
| 152 | a_slices = np.array_split(a_np, groups, axis=1) |
| 153 | w_slices = np.array_split(w_np, groups, axis=0) |
| 154 | b_slices = [ |
| 155 | _conv2d_nchw_python(a_slice, w_slice, stride, padding) |
| 156 | for a_slice, w_slice in zip(a_slices, w_slices) |
| 157 | ] |
| 158 | b_np = np.concatenate(b_slices, axis=1) |
| 159 | return b_np |
nothing calls this directly
no test coverage detected
searching dependent graphs…