Repository: PaddlePaddle/PaddleSeg

Issue:
Kappa系数大于1
版本：Paddle2.2，PaddleSeg版本：2.3.0。在评估模型时发现**Kappa系数大于1**。请问这是什么情况？
如下图所示：
![image](https://user-images.githubusercontent.com/45912889/154666392-f4c4fd54-40ca-4589-8dce-4e867f777c23.png)

配置文件如下：
```batch_size: 2
iters: 80000

model:
  type: DeepLabV3P
  backbone:
    type: ResNet101_vd
    output_stride: 8
    multi_grid: [1, 2, 4]
    pretrained: https://bj.bcebos.com/paddleseg/dygraph/resnet101_vd_ssld.tar.gz
  num_classes: 2
  backbone_indices: [0, 3]
  aspp_ratios: [1, 12, 24, 36]
  aspp_out_channels: 256
  align_corners: False
  pretrained: null


train_dataset:
  type: Dataset
  dataset_root: data/seg_data
  train_path:  data/seg_data/train.txt
  num_classes: 2
  transforms:
    - type: ResizeStepScaling
      min_scale_factor: 0.5
      max_scale_factor: 2.0
      scale_step_size: 0.25
    - type: RandomPaddingCrop
      crop_size: [512, 512]
    - type: RandomHorizontalFlip
    - type: RandomDistort
      brightness_range: 0.4
      contrast_range: 0.4
      saturation_range: 0.4
    - type: Normalize
  mode: train

val_dataset:
  type: Dataset
  dataset_root:  data/seg_data
  val_path:  data/seg_data/val.txt
  num_classes: 2
  transforms:
    - type: Resize
      target_size: [512, 512]
    - type: Normalize
  mode: val


optimizer:
  type: sgd
  momentum: 0.9
  weight_decay: 4.0e-5

lr_scheduler:
  type: PolynomialDecay
  learning_rate: 0.01
  end_lr: 0
  power: 0.9

loss:
  types:
    - type: CrossEntropyLoss
  coef: [1]
```


Discussion:
收到，我们会尽快查看修复。
请问你使用PaddleSeg哪个版本？请在下面代码处，使用print输出三个参数`intersect_area, pred_area, label_area`，看下这三个值是多少，方便我们调试。
https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.4/paddleseg/utils/metrics.py#L207
> 请问你使用PaddleSeg哪个版本？请在下面代码处，使用print输出三个参数`intersect_area, pred_area, label_area`，看下这三个值是多少，方便我们调试。 https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.4/paddleseg/utils/metrics.py#L207

版本：Paddleseg2.3.0

**intersect_area** =  [5477884892  329126204]
**pred_area** =  [5497299265  357850815]
**label_area** =  [5506609503  348540577]
/home/kuan/workspace/PaddleSeg/paddleseg/utils/metrics.py:136: RuntimeWarning: overflow encountered in longlong_scalars
  pe = np.sum(pred_area * label_area) / (total_area * total_area)
2022-02-21 14:51:01 [INFO]      [EVAL] #Images: 885 mIoU: 0.9318 Acc: 0.9918 Kappa: 1.0055 
2022-02-21 14:51:01 [INFO]      [EVAL] Class IoU: 
[0.9913 0.8724]
2022-02-21 14:51:01 [INFO]      [EVAL] Class Acc: 
[0.9965 0.9197]
> 请问你使用PaddleSeg哪个版本？请在下面代码处，使用print输出三个参数`intersect_area, pred_area, label_area`，看下这三个值是多少，方便我们调试。 https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.4/paddleseg/utils/metrics.py#L207

希望bug定位出来以后，能反馈一下原因，非常感谢呀！

Resolving patch:
diff --git a/paddleseg/utils/metrics.py b/paddleseg/utils/metrics.py
--- a/paddleseg/utils/metrics.py
+++ b/paddleseg/utils/metrics.py
@@ -200,9 +200,9 @@ def kappa(intersect_area, pred_area, label_area):
     Returns:
         float: kappa coefficient.
     """
-    intersect_area = intersect_area.numpy()
-    pred_area = pred_area.numpy()
-    label_area = label_area.numpy()
+    intersect_area = intersect_area.numpy().astype(np.float64)
+    pred_area = pred_area.numpy().astype(np.float64)
+    label_area = label_area.numpy().astype(np.float64)
     total_area = np.sum(label_area)
     po = np.sum(intersect_area) / total_area
     pe = np.sum(pred_area * label_area) / (total_area * total_area)


Test patch: