跳至内容

参考资料 ultralytics/models/fastsam/val.py

备注

该文件可在https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/models/ fastsam/val .py。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!



ultralytics.models.fastsam.val.FastSAMValidator

垒球 SegmentationValidator

Ultralytics YOLO 框架中用于快速SAM (Segment Anything Model)分割的自定义验证类。

扩展了 SegmentationValidator 类,专门为快速SAM 自定义验证过程。该类 将任务设置为 "分割",并使用 SegmentMetrics 进行评估。此外,还禁用了绘图功能 以避免在验证过程中出错。

属性

名称 类型 说明
dataloader

用于验证的数据加载器对象。

save_dir str

保存验证结果的目录。

pbar str

进度条对象。

args str

自定义的附加参数。

_callbacks str

验证过程中调用的回调函数列表。

源代码 ultralytics/models/fastsam/val.py
class FastSAMValidator(SegmentationValidator):
    """
    Custom validation class for fast SAM (Segment Anything Model) segmentation in Ultralytics YOLO framework.

    Extends the SegmentationValidator class, customizing the validation process specifically for fast SAM. This class
    sets the task to 'segment' and uses the SegmentMetrics for evaluation. Additionally, plotting features are disabled
    to avoid errors during validation.

    Attributes:
        dataloader: The data loader object used for validation.
        save_dir (str): The directory where validation results will be saved.
        pbar: A progress bar object.
        args: Additional arguments for customization.
        _callbacks: List of callback functions to be invoked during validation.
    """

    def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None):
        """
        Initialize the FastSAMValidator class, setting the task to 'segment' and metrics to SegmentMetrics.

        Args:
            dataloader (torch.utils.data.DataLoader): Dataloader to be used for validation.
            save_dir (Path, optional): Directory to save results.
            pbar (tqdm.tqdm): Progress bar for displaying progress.
            args (SimpleNamespace): Configuration for the validator.
            _callbacks (dict): Dictionary to store various callback functions.

        Notes:
            Plots for ConfusionMatrix and other related metrics are disabled in this class to avoid errors.
        """
        super().__init__(dataloader, save_dir, pbar, args, _callbacks)
        self.args.task = "segment"
        self.args.plots = False  # disable ConfusionMatrix and other plots to avoid errors
        self.metrics = SegmentMetrics(save_dir=self.save_dir, on_plot=self.on_plot)

__init__(dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None)

初始化 FastSAMValidator 类,将任务设置为 "segment",度量值设置为 SegmentMetrics。

参数

名称 类型 说明 默认值
dataloader DataLoader

用于验证的数据加载器。

None
save_dir Path

保存结果的目录。

None
pbar tqdm

进度条用于显示进度。

None
args SimpleNamespace

验证器的配置。

None
_callbacks dict

字典,用于存储各种回调函数。

None
说明

该类禁用了 ConfusionMatrix 和其他相关指标的绘图,以避免出错。

源代码 ultralytics/models/fastsam/val.py
def __init__(self, dataloader=None, save_dir=None, pbar=None, args=None, _callbacks=None):
    """
    Initialize the FastSAMValidator class, setting the task to 'segment' and metrics to SegmentMetrics.

    Args:
        dataloader (torch.utils.data.DataLoader): Dataloader to be used for validation.
        save_dir (Path, optional): Directory to save results.
        pbar (tqdm.tqdm): Progress bar for displaying progress.
        args (SimpleNamespace): Configuration for the validator.
        _callbacks (dict): Dictionary to store various callback functions.

    Notes:
        Plots for ConfusionMatrix and other related metrics are disabled in this class to avoid errors.
    """
    super().__init__(dataloader, save_dir, pbar, args, _callbacks)
    self.args.task = "segment"
    self.args.plots = False  # disable ConfusionMatrix and other plots to avoid errors
    self.metrics = SegmentMetrics(save_dir=self.save_dir, on_plot=self.on_plot)





创建于 2023-11-12,更新于 2023-11-25
作者:glenn-jocher(3)