Exemple #1
0
def ref_deconvolution(x, w, b, base_axis, pad, stride, dilation, group):
    y = []
    for xx in x.reshape((-1,) + x.shape[base_axis:]):
        y += [refs.deconvolution_2d(xx, w, b, pad, stride,
                                    dilation, group)[np.newaxis]]
    y = np.vstack(y)
    return y.reshape(x.shape[:base_axis] + y.shape[1:])
Exemple #2
0
def ref_deconvolution_2d(x,
                         w,
                         b,
                         base_axis,
                         pad,
                         stride,
                         dilation,
                         group,
                         channel_last=False,
                         output_padding=(0, 0)):
    if channel_last:
        transpose_x = refs.ChannelLastToFirstTranspose(x.ndim, len(pad))
        transpose_w = refs.ChannelLastToFirstTranspose(w.ndim, len(pad))
        return transpose_x.inv(
            ref_deconvolution_2d(transpose_x(x), transpose_w(w), b, base_axis,
                                 pad, stride, dilation, group, False,
                                 output_padding))

    y = []
    for xx in x.reshape((-1, ) + x.shape[base_axis:]):
        y += [
            refs.deconvolution_2d(xx,
                                  w,
                                  b,
                                  pad,
                                  stride,
                                  dilation,
                                  group,
                                  output_padding=output_padding)[np.newaxis]
        ]
    y = np.vstack(y)
    return y.reshape(x.shape[:base_axis] + y.shape[1:])
Exemple #3
0
def ref_deconvolution(x, w, b, base_axis, pad, stride, dilation, group):
    y = []
    for xx in x.reshape((-1,) + x.shape[base_axis:]):
        y += [refs.deconvolution_2d(xx, w, b, pad, stride,
                                    dilation, group)[np.newaxis]]
    y = np.vstack(y)
    return y.reshape(x.shape[:base_axis] + y.shape[1:])
def ref_depthwise_deconvolution_2d(x, w, b, base_axis, pad, stride, dilation,
                                   divisor):
    """ implement depthwise deconvolution by using normal deconvolution
    with group = inmaps """
    # insert second dimension to weights
    w = np.expand_dims(w, axis=1)
    y = []

    for xx in x.reshape((-1, ) + x.shape[base_axis:]):
        groups = xx.shape[0] // divisor
        yy = refs.deconvolution_2d(xx, w, b, pad, stride, dilation, groups)
        y.append(yy[np.newaxis])

    y = np.vstack(y)
    return y.reshape(x.shape[:base_axis] + y.shape[1:])