์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

์ฐธ์กฐ ultralytics/models/fastsam/val.py

์ฐธ๊ณ 

์ด ํŒŒ์ผ์€ https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/models/ fastsam/val .py์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ (๐Ÿ› ๏ธ)๋ฅผ ์ œ์ถœํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋„๋ก ๋„์™€์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™!



ultralytics.models.fastsam.val.FastSAMValidator

๊ธฐ์ง€: SegmentationValidator

Ultralytics YOLO ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ๋น ๋ฅธ SAM (์„ธ๊ทธ๋จผํŠธ ์• ๋‹ˆ์”ฝ ๋ชจ๋ธ) ์„ธ๋ถ„ํ™”๋ฅผ ์œ„ํ•œ ์‚ฌ์šฉ์ž ์ง€์ • ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค.

๋น ๋ฅธ SAM ์„ ์œ„ํ•ด ํŠน๋ณ„ํžˆ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‚ฌ์šฉ์ž ์ •์˜ํ•˜๋Š” SegmentationValidator ํด๋ž˜์Šค๋ฅผ ํ™•์žฅํ•ฉ๋‹ˆ๋‹ค. ์ด ํด๋ž˜์Šค ๋Š” ์ž‘์—…์„ '์„ธ๊ทธ๋จผํŠธ'๋กœ ์„ค์ •ํ•˜๊ณ  ํ‰๊ฐ€์— 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)

์ž‘์—…์„ '์„ธ๊ทธ๋จผํŠธ'๋กœ ์„ค์ •ํ•˜๊ณ  ๋ฉ”ํŠธ๋ฆญ์„ SegmentMetrics๋กœ ์„ค์ •ํ•˜์—ฌ FastSAMValidator ํด๋ž˜์Šค๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
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)