显著目标检测metric总结

PR curve  

is plotted based on a set of precision-recall pairs. Given a predicted saliency probability map, its precision and recall scores are computed by comparing its thresholded binary mask against the ground truth mask. The precision and recall of a dataset are computed by averaging the precision and recall scores of those saliency maps. By varying the thresholds from 0 to 1, we can obtain a set of average precision-recall pairs of the dataset.

F-measure

Fβ is used to comprehensively evaluate both precision and recall as:

We set the β2 to 0.3 and report the maximum Fβ (maxFβ) for each dataset similar to previous works

MAE

is the Mean Absolute Error which denotes the average per-pixel difference between a predicted saliency map and its ground truth mask. It is defined as:

weighted F-measure 

is utilized as a comple mentary measure to maxFβ for overcoming the possible unfair comparison caused by “interpolation flaw, dependency flaw and equal-importance flaw”It is defined as:

S-measure 

 is used to evaluate the structure similarity of the predicted non-binary saliency map and the  ground truth. The S-measure is defined as the weighted sum of region-aware Sr and object-aware So structural similarity:

where α is usually set to 0.5.

codes:

class Evaluation_metrics():
    def __init__(self):
        self.beta2 = 0.3 # maxF measure
        self.alpha = 0.5 # S measure
        self.nb_grid_pr = 255 # pr score
    
    
    def cal_total_metrics(self, pred, gt):
        ## pred and gt should have the same dimension: H * W
        # MAE
        mae = self.cal_mae(pred, gt)
        
        # MaxF measure
        prec, recall = self._eval_pr(pred, gt, 255)
        f_score = (1 + self.beta2) * prec * recall / (self.beta2 * prec + recall)
        f_score[f_score != f_score] = 0  # for Nan
        max_f = f_score.max().item()
        
        # AvgF measure
        avg_f = f_score.mean().item()
        
        # S measure
        gt_mean = gt.mean()
        if gt_mean == 0:
            Q = 1.0 - pred.mean()
        elif gt_mean == 1:
            Q = pred.mean()
        else:
            gt[gt >= 0.5] = 1
            gt[gt < 0.5] = 0
            Q = self.alpha * self._S_object(pred, gt) + (1 - self.alpha) * self._S_region(pred, gt)
            if Q.item() < 0:
                Q = torch.FloatTensor([0.0])
        s_score = Q.item()

        return mae, max_f, avg_f, s_score

    def _eval_pr(self, y_pred, y, num):
        
        prec, recall = torch.zeros(self.nb_grid_pr), torch.zeros(self.nb_grid_pr)
        thlist = torch.linspace(0, 1 - 1e-10, self.nb_grid_pr)
        for i in range(self.nb_grid_pr):
            y_temp = (y_pred >= thlist[i]).float()
            tp = (y_temp * y).sum()
            prec[i], recall[i] = tp / (y_temp.sum() + 1e-20), tp / (y.sum() + 1e-20)
        return prec, recall

    def _S_object(self, pred, gt):
        fg = torch.where(gt == 0, torch.zeros_like(pred), pred)
        bg = torch.where(gt == 1, torch.zeros_like(pred), 1 - pred)
        o_fg = self._object(fg, gt)
        o_bg = self._object(bg, 1 - gt)
        u = gt.mean()
        Q = u * o_fg + (1 - u) * o_bg
        return Q

    def _object(self, pred, gt):
        x = pred[gt == 1]
        mean_x = x.mean()
        sigma_x = x.std()
        score = 2.0 * mean_x / (mean_x * mean_x + 1.0 + sigma_x + 1e-20)

        return score

    def _S_region(self, pred, gt):
        X, Y = self._centroid(gt)
        gt1, gt2, gt3, gt4, w1, w2, w3, w4 = self._divideGT(gt, X, Y)
        p1, p2, p3, p4 = self._dividePrediction(pred, X, Y)
        Q1 = self._ssim(p1, gt1)
        Q2 = self._ssim(p2, gt2)
        Q3 = self._ssim(p3, gt3)
        Q4 = self._ssim(p4, gt4)
        Q = w1 * Q1 + w2 * Q2 + w3 * Q3 + w4 * Q4
        return Q

    def _centroid(self, gt):
        h, w = gt.size()[-2:]
        if gt.sum() == 0:
            X = torch.eye(1) * round(w / 2)
            Y = torch.eye(1) * round(h / 2)
        else:
            total = gt.sum()
            i = torch.from_numpy(np.arange(0, w)).float()
            j = torch.from_numpy(np.arange(0, h)).float()
            X = torch.round((gt.sum(dim=0) * i).sum() / total)
            Y = torch.round((gt.sum(dim=1) * j).sum() / total)
        return X.long(), Y.long()

    def _divideGT(self, gt, X, Y):
        h, w = gt.size()
        area = h * w
        LT = gt[:Y, :X]
        RT = gt[:Y, X:w]
        LB = gt[Y:h, :X]
        RB = gt[Y:h, X:w]
        X = X.float()
        Y = Y.float()
        w1 = X * Y / area
        w2 = (w - X) * Y / area
        w3 = X * (h - Y) / area
        w4 = 1 - w1 - w2 - w3
        return LT, RT, LB, RB, w1, w2, w3, w4

    def _dividePrediction(self, pred, X, Y):
        h, w = pred.size()
        LT = pred[:Y, :X]
        RT = pred[:Y, X:w]
        LB = pred[Y:h, :X]
        RB = pred[Y:h, X:w]
        return LT, RT, LB, RB

    def _ssim(self, pred, gt):
        gt = gt.float()
        h, w = pred.size()
        N = h * w
        x = pred.mean()
        y = gt.mean()
        sigma_x2 = ((pred - x) * (pred - x)).sum() / (N - 1 + 1e-20)
        sigma_y2 = ((gt - y) * (gt - y)).sum() / (N - 1 + 1e-20)
        sigma_xy = ((pred - x) * (gt - y)).sum() / (N - 1 + 1e-20)

        alpha = 4 * x * y * sigma_xy
        beta = (x * x + y * y) * (sigma_x2 + sigma_y2)

        if aplha != 0:
            Q = alpha / (beta + 1e-20)
        elif alpha == 0 and beta == 0:
            Q = 1.0
        else:
            Q = 0
        return Q


 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
基于神经网络的红外弱小目标检测方法已经被广泛研究和应用。其中,卷积神经网络(CNN)是一种常用的神经网络模型,它可以自动从数据中学习特征,并在图像分类和目标检测等任务中取得了很好的效果。以下是一个基于CNN的红外弱小目标检测方法的简要步骤: 1. 数据准备:收集并标注红外图像数据集,包括弱小目标和背景图像。 2. 数据增强:对数据集进行增强操作,如旋转、翻转、缩放等,以扩充数据集并提高模型的鲁棒性。 3. 神经网络设计:设计一个适合红外弱小目标检测的CNN模型,包括卷积层、池化层、全连接层等。 4. 神经网络训练:使用数据集对CNN模型进行训练,以学习红外弱小目标的特征。 5. 目标检测:使用训练好的CNN模型对新的红外图像进行目标检测,输出弱小目标的位置和类别。 6. 模型评估:对模型进行评估,包括准确率、召回率、F1值等指标。 以下是一个基于TensorFlow的CNN模型的代码示例: ```python import tensorflow as tf # 定义CNN模型 def cnn_model(features, labels, mode): input_layer = tf.reshape(features["x"], [-1, 28, 28, 1]) conv1 = tf.layers.conv2d(inputs=input_layer, filters=32, kernel_size=[5, 5], padding="same", activation=tf.nn.relu) pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2) conv2 = tf.layers.conv2d(inputs=pool1, filters=64, kernel_size=[5, 5], padding="same", activation=tf.nn.relu) pool2 = tf.layers.max_pooling2d(inputs=conv2, pool_size=[2, 2], strides=2) pool2_flat = tf.reshape(pool2, [-1, 7 * 7 * 64]) dense = tf.layers.dense(inputs=pool2_flat, units=1024, activation=tf.nn.relu) dropout = tf.layers.dropout(inputs=dense, rate=0.4, training=mode == tf.estimator.ModeKeys.TRAIN) logits = tf.layers.dense(inputs=dropout, units=10) # 预测 predictions = { "classes": tf.argmax(input=logits, axis=1), "probabilities": tf.nn.softmax(logits, name="softmax_tensor") } # 预测模式 if mode == tf.estimator.ModeKeys.PREDICT: return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions) # 计算损失 loss = tf.losses.sparse_softmax_cross_entropy(labels=labels, logits=logits) # 训练模式 if mode == tf.estimator.ModeKeys.TRAIN: optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001) train_op = optimizer.minimize(loss=loss, global_step=tf.train.get_global_step()) return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op) # 评估模式 eval_metric_ops = { "accuracy": tf.metrics.accuracy(labels=labels, predictions=predictions["classes"]) } return tf.estimator.EstimatorSpec(mode=mode, loss=loss, eval_metric_ops=eval_metric_ops) # 加载数据集 mnist = tf.contrib.learn.datasets.load_dataset("mnist") train_data = mnist.train.images train_labels = np.asarray(mnist.train.labels, dtype=np.int32) eval_data = mnist.test.images eval_labels = np.asarray(mnist.test.labels, dtype=np.int32) # 创建Estimator mnist_classifier = tf.estimator.Estimator(model_fn=cnn_model, model_dir="/tmp/mnist_convnet_model") # 训练模型 train_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": train_data}, y=train_labels, batch_size=100, num_epochs=None, shuffle=True) mnist_classifier.train(input_fn=train_input_fn, steps=20000) # 评估模型 eval_input_fn = tf.estimator.inputs.numpy_input_fn(x={"x": eval_data}, y=eval_labels, num_epochs=1, shuffle=False) eval_results = mnist_classifier.evaluate(input_fn=eval_input_fn) print(eval_results) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lyttonkeepgoing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值