yolov8 选择并保存的依据 (附带修改记录,) + 设置早停

时间:2025-04-02 09:08:42

在ultralytics/utils/文件中 修改各个指标的影响权重

    def fitness(self):
        """Model fitness as a weighted combination of metrics."""
        w = [0.25, 0.25, 0.35, 0.15]  # weights for [P, R, mAP@0.5, mAP@0.75]
        return ((self.mean_results()) * w).sum()

P, R, mAP@0.5, mAP@0.75,并且设权重为w = [0.25, 0.25, 0.35, 0.15]了,如果需要修改,就像我一样先改上面的权重。再按照下面修改:  设置你要评估的指标


    def mean_results(self):
        """Mean of results, return mp, mr, map50, map."""
        return [, , self.map50, self.map75]

还是这个文件,代码在上面,改成你需要的指标。在这就已经改完了。

在ultralytics/models/yolo/detect/文件中     训练结束时输出你想要的指标结果

    def get_desc(self):
        """Return a formatted string summarizing class metrics of YOLO model."""
        return ("%22s" + "%11s" * 6) % ("Class", "Images", "Instances", "Box(P", "R", "mAP50", "mAP75)")

像我一样把结果输出的地方也改了(改不改都可以,改了就会像下面一样显示你要评估的指标了)

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      7/300       4.2G       4.77      4.595      1.872         15        640: 100%|██████████| 22/22 [00:06<00:00,  3.39it/s]
                 Class     Images  Instances      Box(P          R      mAP50     mAP75): 100%|██████████| 3/3 [00:00<00:00,  5.38it/s]
                   all         86        109      0.493       0.55      0.392     0.0121
  0%|          | 0/22 [00:00<?, ?it/s]
      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      8/300       4.2G      4.761      4.212      1.763          6        640: 100%|██████████| 22/22 [00:06<00:00,  3.34it/s]
                 Class     Images  Instances      Box(P          R      mAP50     mAP75): 100%|██████████| 3/3 [00:00<00:00,  5.26it/s]
                   all         86        109      0.432      0.505      0.363     0.0247

再附带一个吧,设置早停epoch:ultralytics/cfg/ 中改 patience