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计算
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是最后一个示例中的第一列和第三列向量。让我们将此公式拆分,以确保其非常清晰:
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]]