Exemple #1
0
Fichier : nn.py Projet : x724/cgt
def conv2d(x_BKRC, f_LKrc, kernelshape, pad=(0, 0), stride=(1, 1)):
    col_BmnZ = im2col(x_BKRC, kernelshape, pad, stride)
    L, K, r, c = f_LKrc.shape
    f_LZ = f_LKrc.reshape([L, K * r * c])
    B, m, n, Z = col_BmnZ.shape
    col_Bmn_Z = col_BmnZ.reshape([B * m * n, Z])
    col_Bmn_L = core.Result(core.Mul22(False, True), [col_Bmn_Z, f_LZ])
    return col_Bmn_L.reshape([B, m, n, L]).transpose([0, 3, 1, 2])
Exemple #2
0
def conv2d(x_BKRC, f_LKrc, kernelshape, pad=(0, 0), stride=(1, 1)):
    devtype = cgt.get_config()["default_device"].devtype
    L, K, r, c = f_LKrc.shape
    if devtype == "gpu":
        b_1K11 = cgt.zeros((1, L, 1, 1), cgt.floatX)
        return core.Result(
            cudnn_ops.CudnnConvForward(pad[0], pad[1], stride[0], stride[1]),
            [x_BKRC, f_LKrc, b_1K11])
    else:
        assert devtype == "cpu"
        col_BmnZ = im2col(x_BKRC, kernelshape, pad, stride)
        f_LZ = f_LKrc.reshape([L, K * r * c])
        B, m, n, Z = col_BmnZ.shape
        col_Bmn_Z = col_BmnZ.reshape([B * m * n, Z])
        col_Bmn_L = core.Result(core.Mul22(False, True), [col_Bmn_Z, f_LZ])
        return col_Bmn_L.reshape([B, m, n, L]).transpose([0, 3, 1, 2])
Exemple #3
0
def matmat11a(X, Y):
    if isinstance(X, np.ndarray):
        return np.dot(X.T, Y.T).sum()
    else:
        return sum(core.Result(core.Mul22(True, True), [X, Y]))
Exemple #4
0
def matmat00a(X, Y):
    if isinstance(X, np.ndarray):
        return np.dot(X, Y).sum()
    else:
        return sum(core.Result(core.Mul22(False, False), [X, Y]))