예제 #1
0
def ref_sum_pooling_2d(x, kernel, stride, ignore_border, pad):
    y = []
    for xx in x.reshape((-1,) + x.shape[-3:]):
        if xx.ndim == 2:
            xx = xx[np.newaxis]
        y += [refs.pooling_2d(xx, 'sum', kernel, stride,
                              pad, ignore_border)[np.newaxis]]
    y = np.vstack(y)
    if x.ndim == 2:
        y = np.squeeze(y, 1)
    return y.reshape(x.shape[:-3] + y.shape[1:])
예제 #2
0
def ref_max_pooling(x, kernel, stride, ignore_border, pad):
    # Only 2d
    y = []
    for xx in x.reshape((-1,) + x.shape[-3:]):
        if xx.ndim == 2:
            xx = xx[np.newaxis]
        y += [refs.pooling_2d(xx, 'max', kernel, stride,
                              pad, ignore_border)[np.newaxis]]
    y = np.vstack(y)
    if x.ndim == 2:
        y = np.squeeze(y, 1)
    return y.reshape(x.shape[:-3] + y.shape[1:])
def ref_average_pooling(x, kernel, stride, ignore_border, pad, including_pad):
    # Only 2d
    y = []
    for xx in x.reshape((-1, ) + x.shape[-3:]):
        if xx.ndim == 2:
            xx = xx[np.newaxis]
        y += [
            refs.pooling_2d(xx, 'average', kernel, stride, pad, ignore_border,
                            including_pad)[np.newaxis]
        ]
    y = np.vstack(y)
    if x.ndim == 2:
        y = np.squeeze(y, 1)
    return y.reshape(x.shape[:-3] + y.shape[1:])