1-utils_metrics.py用在train.py中做指标衡量,现在想在推理(predict.py)的时候衡量一下指标
2-调研眼睛部位的单独分割。
https://blog.csdn.net/qq_40234695/article/details/88633094
衡量图像语义分割准确率主要有三种方法:
像素准确率(pixel accuracy, PA)
平均像素准确率(mean pixel accuracy, MPA)
平均IOU(Mean Intersection over Union, MIOU )
像素准确率(Pixel Accuracy,PA)、
类别像素准确率(Class Pixel Accuray,CPA)、
类别平均像素准确率(Mean Pixel Accuracy,MPA)、
交并比(Intersection over Union,IoU)、
平均交并比(Mean Intersection over Union,MIoU),
其计算都是建立在混淆矩阵(Confusion Matrix)的基础上。————————————————
原文链接:https://blog.csdn.net/weixin_38353277/article/details/121029978
from ultralytics.engine.model import Model
from ultralytics.models import yolo \# noqa
from ultralytics.nn.tasks import ClassificationModel, DetectionModel, PoseModel, SegmentationModel
class YOLO(Model):
"""YOLO (You Only Look Once) object detection model."""
@property
def task_map(self):
"""Map head to model, trainer, validator, and predictor classes."""
return {
'classify': {
'model': ClassificationModel,
'trainer': yolo.classify.ClassificationTrainer,
'validator': yolo.classify.ClassificationValidator,
'predictor': yolo.classify.ClassificationPredictor, },
'detect': {
'model': DetectionModel,
'trainer': yolo.detect.DetectionTrainer,
'validator': yolo.detect.DetectionValidator,
'predictor': yolo.detect.DetectionPredictor, },
'segment': {
'model': SegmentationModel,
'trainer': yolo.segment.SegmentationTrainer,
'validator': yolo.segment.SegmentationValidator,
'predictor': yolo.segment.SegmentationPredictor, },
'pose': {
'model': PoseModel,
'trainer': yolo.pose.PoseTrainer,
'validator': yolo.pose.PoseValidator,
'predictor': yolo.pose.PosePredictor, }, }
YOLO类继承了ultralytics文件里面的engine文件里面的model.py文件里面的 Model类别。这个时候应该去看from ultralytics.engine.model import Model里面Model里的原码(但是下面的@property下面的代码又是什么意思呢)。
from yolov8.ultralytics import YOLO
from segment_anything.utils.transforms import ResizeLongestSide
from segment_anything import SamPredictor, sam_model_registry
class TongueSeg():
def __init__(self, device = 'cuda:0', model_path="/share1/luli/yolov8SAM/pretrained_model") -> None:
self.device = device
self.model_type = 'vit_b'
self.checkpoint = model_path+'/tonguesam.pth'
self.det_model=YOLO('/share1/luli/yolov8/runs/detect/train20/weights/best.pt', task='detect')
self.sam_model = sam_model_registry[self.model_type](checkpoint=self.checkpoint).to(device)
self.det_model=YOLO('/share1/luli/yolov8/runs/detect/train20/weights/best.pt', task='detect')
是from yolov8.ultralytics import YOLO,导入YOLO--->>>点击继续入YOLO,进入到下面这个地方:
from ultralytics.engine.model import Model
from ultralytics.models import yolo # noqa
from ultralytics.nn.tasks import ClassificationModel, DetectionModel, PoseModel, SegmentationModel
class YOLO(Model):
上面又是继承了Model,Model是从ultralytics.engine.model里面导入的,这时候要点击Model去查看源码,如下:
import inspect
import sys
from pathlib import Path
from typing import Union
from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir
from ultralytics.hub.utils import HUB_WEB_ROOT
from ultralytics.nn.tasks import attempt_load_one_weight, guess_model_task, nn, yaml_model_load
from ultralytics.utils import ASSETS, DEFAULT_CFG_DICT, LOGGER, RANK, callbacks, checks, emojis, yaml_load
class Model(nn.Module):
上面导入了cfg,nn.tasks,utils
utils里面有个__init__.py函数,函数上面有个callbacks文件夹,文件夹里面有很多的