Python——PCA主成分分析

PCA主成分分析

输入X,降低后的维度k

def PCA_Batch_Feat(X, k, center=True):
    """
    param X: BxCxHxW
    param k: scalar
    return:
    """
    B, C, H, W = X.shape
    X = X.permute(0, 2, 3, 1)  # BxHxWxC
    X = X.reshape(B, H * W, C)
    U, S, V = torch.pca_lowrank(X, center=center)
    Y = torch.bmm(X, V[:, :, :k])
    Y = Y.reshape(B, H, W, k)
    Y = Y.permute(0, 3, 1, 2)  # BxHxWxk
    return Y

你可能感兴趣的:(深度学习,pytorch,dnn,深度学习)