1.复习了几个numpy函数,对参数里面的维度加深理解
1.np.mean(),求平均,若axis为元组,说明是在元组说明的维度上进行求均值
e.g.
mean_sal = np.mean(pred,(1,2))
其中pred为[length,height,width]三维度的矩阵,上述代码操作为对每个图像矩阵进行求均值,最终得到mean_sal变为[length]数组
2.np.multiply(),是每个对应位置的元素相乘,可用于求{0,1}值的两张图都为一的像素点数量(外面加一个np.sum)
3.np.sum(),求和
4.np.logic_and(),求逻辑与,用于求TP,FP,TN数据
5.np.equal(X, number),返回维度相同的True和False图,条件为每个元素是否等于number
2.掌握了显著性目标检测中两个常用的性能评估指标MAE与F-measure的实现方法
MAE:
def get_mae(pred, gt, in_type='numpy'):
"""Get average MAE for evaluation.
:param pred: predicted saliency map, if in_type='file', pred is the path to images,
if in_type='numpy' it should be a 3D ndarray having dtype np.float and of shape [length, height, width].
:param gt: ground truth saliency map, if in_type='file', gt is the path to images
if in_type='numpy' it should be a 3D ndarray having dtype np.uint8 and of shape [length, height, width].
:param in_type: value in {'file', 'numpy'}, default set to 'numpy'.
:return: one float value, indicating average MAE for evaluation.
"""
if in_type == 'file':
pred_names = os.listdir(pred)
pred_list = []
for name in pred_names:
img = np.array(Image.open(name, 'r'))
img = img.astype(np.float)
pred_list.append(img)
pred_list = np.array(pred_list)
gt_names = os.listdir(gt)
gt_list = []
for name in gt_names:
gt = np