Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Statistics 统计学对计算机视觉的帮助_Statistics_Pattern Matching_Computer Vision_Pattern Recognition - Fatal编程技术网

Statistics 统计学对计算机视觉的帮助

Statistics 统计学对计算机视觉的帮助,statistics,pattern-matching,computer-vision,pattern-recognition,Statistics,Pattern Matching,Computer Vision,Pattern Recognition,我正在做计算机视觉领域的毕业设计,我只修了一门统计学课程,讨论了非常基本的概念,现在我在相当高级的主题上面临更多的困难,所以我需要帮助(书籍、教程、课程等等)掌握和复习统计学中的基本思想和概念,然后深入研究计算机视觉中使用的细节(统计细节)。我想你需要一些关于模式识别和机器学习领域的知识。如果是的话,我喜欢,这是一个很好的介绍,并谈了一些关于简历的应用。不过,它也假设你有一些概率论的基本知识。如果您没有,我建议。您可以使用以下示例计算误报/误报等: import torch def conf

我正在做计算机视觉领域的毕业设计,我只修了一门统计学课程,讨论了非常基本的概念,现在我在相当高级的主题上面临更多的困难,所以我需要帮助(书籍、教程、课程等等)掌握和复习统计学中的基本思想和概念,然后深入研究计算机视觉中使用的细节(统计细节)。

我想你需要一些关于模式识别和机器学习领域的知识。如果是的话,我喜欢,这是一个很好的介绍,并谈了一些关于简历的应用。不过,它也假设你有一些概率论的基本知识。如果您没有,我建议。

您可以使用以下示例计算误报/误报等:

import torch


def confusion(prediction, truth):
    """ Returns the confusion matrix for the values in the `prediction` and `truth`
    tensors, i.e. the amount of positions where the values of `prediction`
    and `truth` are
    - 1 and 1 (True Positive)
    - 1 and 0 (False Positive)
    - 0 and 0 (True Negative)
    - 0 and 1 (False Negative)
    """

    confusion_vector = prediction / truth
    # Element-wise division of the 2 tensors returns a new tensor which holds a
    # unique value for each case:
    #   1     where prediction and truth are 1 (True Positive)
    #   inf   where prediction is 1 and truth is 0 (False Positive)
    #   nan   where prediction and truth are 0 (True Negative)
    #   0     where prediction is 0 and truth is 1 (False Negative)

    true_positives = torch.sum(confusion_vector == 1).item()
    false_positives = torch.sum(confusion_vector == float('inf')).item()
    true_negatives = torch.sum(torch.isnan(confusion_vector)).item()
    false_negatives = torch.sum(confusion_vector == 0).item()

    return true_positives, false_positives, true_negatives, false_negatives
您可以使用nn.BCEWithLogitsLoss(因此删除sigmoid)并将pos_weight设置为>1以增加召回率。或者进一步优化它,使用以下方法惩罚模型的误报:

def Dice(y_true, y_pred):
    """Returns Dice Similarity Coefficient for ground truth and predicted masks."""
    #print(y_true.dtype)
    #print(y_pred.dtype)
    y_true = np.squeeze(y_true)/255
    y_pred = np.squeeze(y_pred)/255
    y_true.astype('bool')
    y_pred.astype('bool')
    intersection = np.logical_and(y_true, y_pred).sum()
    return ((2. * intersection.sum()) + 1.) / (y_true.sum() + y_pred.sum() + 1.)
已解释IOU计算

  • 真阳性计数(TP)
  • 计数假阳性(FP)
  • 统计假阴性(FN)
  • 交叉口=TP
  • 联合=TP+FP+FN
  • IOU=交叉点/并集
  • 左边是我们的基本事实,右边是我们的预测。左侧突出显示的单元格说明了我们在右侧查看哪个类的统计信息。右侧的突出显示为奶油色的真阳性,橙色的假阳性,黄色的假阴性(请注意,所有其他的都是真阴性-它们被预测为这个单独的类别,不应基于基本事实)

    对于0类,只有4x4矩阵的顶行应预测为零。这是一个相当简化的真实地面真相。实际上,零可能在矩阵中的任何位置。在右边,我们看到1,0,0,这意味着第一个是假阴性,但其他三个是真阳性(也就是交叉点的3)。从那里,我们需要找到错误预测零的任何其他地方,我们注意到第二行发生一次,第四行发生两次,总共三次误报。 为了得到联合,我们将TP(3)、FP(3)和FN(1)相加得到7。因此,该类的IOU为3/7

    如果我们对所有类进行此操作,并将欠条平均,我们会得到:

    Mean IOU = [(3/7) + (2/6) + (3/4) + (1/6)] / 4 = 0.420
    
    您还需要学习如何提取地图的统计数据(平均平均精度)

  • 计算协方差矩阵

    变量的方差描述值的分散程度。协方差是一种衡量两个变量之间依赖程度的指标

    正协方差意味着当第二个变量的值也较大时,第一个变量的值较大。负协方差的意思正好相反:一个变量的大值与另一个变量的小值相关联

    协方差值取决于变量的尺度,因此很难对其进行分析。可以使用更容易解释的相关系数。相关系数就是归一化协方差

    正协方差意味着一个变量的大值与另一个变量的大值相关联(左)。负协方差意味着一个变量的大值与另一个变量的小值相关联(右)。 协方差矩阵是一个汇总一组向量的方差和协方差的矩阵,它可以告诉你很多关于变量的事情。对角线对应于每个向量的方差:

    矩阵A及其协方差矩阵。对角线对应于每个列向量的方差。让我们用方差公式检查一下:

    n表示向量的长度,x表示向量的平均值。例如,A的第一列向量的方差为:

    这是协方差矩阵的第一个单元。对角线上的第二个元素对应于第二列向量与A的方差,依此类推

    注:从矩阵A中提取的向量对应于A的列

    其他单元格对应于A中两列向量之间的协方差。例如,第一列和第三列之间的协方差位于协方差矩阵中,作为列1和行3(或列3和行1):

    协方差矩阵中的位置。列对应第一个变量,行对应第二个变量(或相反)。A的第一列和第三列向量之间的协方差是第1列和第3行中的元素(或相反=相同值)

    让我们检查A的第一列和第三列向量之间的协方差是否等于-2.67。两个变量X和Y之间的协方差公式为:

    变量X和Y是最后一个示例中的第一列和第三列向量。让我们将此公式拆分,以确保其非常清晰:

  • 求和符号(∑)意味着我们将迭代向量的元素。我们将从第一个元素(i=1)开始,计算X的第一个元素减去向量X的平均值:

  • 将结果乘以Y的第一个元素减去向量Y的平均值:

  • 对向量的每个元素重复该过程,并计算所有结果的总和:

  • 除以向量中的元素数

  • 示例-让我们从矩阵A开始:

    我们将计算第一列和第三列向量之间的协方差: 及

    也就是x̄=3,n=4,n=3,所以我们有:

    代码示例-

    使用NumPy,可以使用
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    A = np.array([[1, 3, 5], [5, 4, 1], [3, 8, 6]])
    
    np.cov(A, rowvar=False, bias=True)
    
    def calculateCovariance(X):
        meanX = np.mean(X, axis = 0)
        lenX = X.shape[0]
        X = X - meanX
        covariance = X.T.dot(X)/lenX
        return covariance
    
    print(calculateCovariance(A))
    
    array([[ 2.66666667, 0.66666667, -2.66666667],
           [ 0.66666667, 4.66666667, 2.33333333],
           [-2.66666667, 2.33333333, 4.66666667]])
    
    def plotDataAndCov(data):
    ACov = np.cov(data, rowvar=False, bias=True)
    print 'Covariance matrix:\n', ACov
    
    fig, ax = plt.subplots(nrows=1, ncols=2)
    fig.set_size_inches(10, 10)
    
    ax0 = plt.subplot(2, 2, 1)
    
    # Choosing the colors
    cmap = sns.color_palette("GnBu", 10)
    sns.heatmap(ACov, cmap=cmap, vmin=0)
    
    ax1 = plt.subplot(2, 2, 2)
    
    # data can include the colors
    if data.shape[1]==3:
        c=data[:,2]
    else:
        c="#0A98BE"
    ax1.scatter(data[:,0], data[:,1], c=c, s=40)
    
    # Remove the top and right axes from the data plot
    ax1.spines['right'].set_visible(False)
    ax1.spines['top'].set_visible(False)
    
    np.random.seed(1234)
    a1 = np.random.normal(2, 1, 300)
    a2 = np.random.normal(1, 1, 300)
    A = np.array([a1, a2]).T
    A.shape
    
    A[:10,:]
    
    array([[ 2.47143516, 1.52704645],
           [ 0.80902431, 1.7111124 ],
           [ 3.43270697, 0.78245452],
           [ 1.6873481 , 3.63779121],
           [ 1.27941127, -0.74213763],
           [ 2.88716294, 0.90556519],
           [ 2.85958841, 2.43118375],
           [ 1.3634765 , 1.59275845],
           [ 2.01569637, 1.1702969 ],
           [-0.24268495, -0.75170595]])
    
    sns.distplot(A[:,0], color="#53BB04")
    sns.distplot(A[:,1], color="#0A98BE")
    plt.show()
    plt.close()
    
    plotDataAndCov(A)
    plt.show()
    plt.close()
    
    
    Covariance matrix:
    [[ 0.95171641 -0.0447816 ]
     [-0.0447816 0.87959853]]
    
    np.random.seed(1234)
    b1 =  np.random.normal(3, 1, 300)
    b2 = b1 + np.random.normal(7, 1, 300)/2.
    B = np.array([b1, b2]).T
    plotDataAndCov(B)
    plt.show()
    plt.close()
    
    
    Covariance matrix:
    [[ 0.95171641 0.92932561]
     [ 0.92932561 1.12683445]]