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:

NameTypeDescription
dataloader

The data loader object used for validation.

save_dirstr

The directory where validation results will be saved.

pbarstr

A progress bar object.

argsstr

Additional arguments for customization.

_callbacksstr

List of callback functions to be invoked during validation.

Parameters:

NameTypeDescriptionDefault
dataloaderDataLoader

Dataloader to be used for validation.

None
save_dirPath

Directory to save results.

None
pbartqdm

Progress bar for displaying progress.

None
argsSimpleNamespace

Configuration for the validator.

None
_callbacksdict

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 1 year ago ✏️ Updated 2 months ago