Skip to content

Reference for ultralytics/models/fastsam/val.py

Note

This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/fastsam/val.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!


ultralytics.models.fastsam.val.FastSAMValidator

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

Bases: 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:

Name Type Description
dataloader

The data loader object used for validation.

save_dir str

The directory where validation results will be saved.

pbar str

A progress bar object.

args str

Additional arguments for customization.

_callbacks str

List of callback functions to be invoked during validation.

Parameters:

Name Type Description Default
dataloader DataLoader

Dataloader to be used for validation.

None
save_dir Path

Directory to save results.

None
pbar tqdm

Progress bar for displaying progress.

None
args SimpleNamespace

Configuration for the validator.

None
_callbacks dict

Dictionary to store various callback functions.

None
Notes

Plots for ConfusionMatrix and other related metrics are disabled in this class to avoid errors.

Source code in 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)




📅 Created 11 months ago ✏️ Updated 1 month ago