class_docstr: The ``SemanticSegmentationData`` class is a :class:`~flash.core.data.data_module.DataModule` with a set of
  classmethods for loading data for semantic segmentation.
docstr: Load the :class:`~flash.image.segmentation.data.SemanticSegmentationData` from FiftyOne ``SampleCollection``
  objects.
  
  The supported file extensions are: ``.jpg``, ``.jpeg``, ``.png``, ``.ppm``, ``.bmp``, ``.pgm``, ``.tif``,
  ``.tiff``, ``.webp``, and ``.npy``.
  Mask image file paths will be extracted from the ``label_field`` in the ``SampleCollection`` objects.
  To learn how to customize the transforms applied for each stage, read our
  :ref:`customizing transforms guide <customizing_transforms>`.
  
  Args:
      train_dataset: The ``SampleCollection`` to use when training.
      val_dataset: The ``SampleCollection`` to use when validating.
      test_dataset: The ``SampleCollection`` to use when testing.
      predict_dataset: The ``SampleCollection`` to use when predicting.
      label_field: The field in the ``SampleCollection`` objects containing the targets.
      input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
      num_classes: The number of segmentation classes.
      labels_map: An optional mapping from class to RGB tuple indicating the colour to use when visualizing masks.
          If not provided, a random mapping will be used.
      transform: The :class:`~flash.core.data.io.input_transform.InputTransform` type to use.
      transform_kwargs: Dict of keyword arguments to be provided when instantiating the transforms.
      data_module_kwargs: Additional keyword arguments to provide to the
        :class:`~flash.core.data.data_module.DataModule` constructor.
  
  Returns:
      The constructed :class:`~flash.image.segmentation.data.SemanticSegmentationData`.
  
  Examples
  ________
  
  .. testsetup::
  
      >>> from PIL import Image
      >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
      >>> _ = [rand_image.save(f"image_{i}.png") for i in range(1, 4)]
      >>> _ = [rand_image.save(f"predict_image_{i}.png") for i in range(1, 4)]
  
  .. doctest::
  
      >>> import numpy as np
      >>> import fiftyone as fo
      >>> from flash import Trainer
      >>> from flash.image import SemanticSegmentation, SemanticSegmentationData
      >>> train_dataset = fo.Dataset.from_images(
      ...     ["image_1.png", "image_2.png", "image_3.png"]
      ... )  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      <BLANKLINE>
      ...
      >>> samples = [train_dataset[filepath] for filepath in train_dataset.values("filepath")]
      >>> for sample in samples:
      ...     sample["ground_truth"] = fo.Segmentation(mask=np.random.randint(0, 10, (64, 64), dtype="uint8"))
      ...     sample.save()
      ...
      >>> predict_dataset = fo.Dataset.from_images(
      ...     ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"]
      ... )  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      <BLANKLINE>
      ...
      >>> datamodule = SemanticSegmentationData.from_fiftyone(
      ...     train_dataset=train_dataset,
      ...     predict_dataset=predict_dataset,
      ...     transform_kwargs=dict(image_size=(128, 128)),
      ...     num_classes=10,
      ...     batch_size=2,
      ... )
      >>> datamodule.num_classes
      10
      >>> model = SemanticSegmentation(backbone="resnet18", num_classes=datamodule.num_classes)
      >>> trainer = Trainer(fast_dev_run=True)
      >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Training...
      >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Predicting...
  
  .. testcleanup::
  
      >>> import os
      >>> _ = [os.remove(f"image_{i}.png") for i in range(1, 4)]
      >>> _ = [os.remove(f"predict_image_{i}.png") for i in range(1, 4)]
docstr_tok: ["Load","the",":","class",":","`","~flash.image.segmentation.data.SemanticSegmentationData","`","from","FiftyOne","``","SampleCollection","``","objects",".","The","supported","file","extensions","are",":","``",".jpg","``",",","``",".jpeg","``",",","``",".png","``",",","``",".ppm","``",",","``",".bmp","``",",","``",".pgm","``",",","``",".tif","``",",","``",".tiff","``",",","``",".webp","``",",","and","``",".npy","``",".","Mask","image","file","paths","will","be","extracted","from","the","``","label_field","``","in","the","``","SampleCollection","``","objects",".","To","learn","how","to","customize","the","transforms","applied","for","each","stage",",","read","our",":","ref",":","`","customizing","transforms","guide","<","customizing_transforms",">","`",".","Args",":","train_dataset",":","The","``","SampleCollection","``","to","use","when","training",".","val_dataset",":","The","``","SampleCollection","``","to","use","when","validating",".","test_dataset",":","The","``","SampleCollection","``","to","use","when","testing",".","predict_dataset",":","The","``","SampleCollection","``","to","use","when","predicting",".","label_field",":","The","field","in","the","``","SampleCollection","``","objects","containing","the","targets",".","input_cls",":","The",":","class",":","`","~flash.core.data.io.input.Input","`","type","to","use","for","loading","the","data",".","num_classes",":","The","number","of","segmentation","classes",".","labels_map",":","An","optional","mapping","from","class","to","RGB","tuple","indicating","the","colour","to","use","when","visualizing","masks",".","If","not","provided",",","a","random","mapping","will","be","used",".","transform",":","The",":","class",":","`","~flash.core.data.io.input_transform.InputTransform","`","type","to","use",".","transform_kwargs",":","Dict","of","keyword","arguments","to","be","provided","when","instantiating","the","transforms",".","data_module_kwargs",":","Additional","keyword","arguments","to","provide","to","the",":","class",":","`","~flash.core.data.data_module.DataModule","`","constructor",".","Returns",":","The","constructed",":","class",":","`","~flash.image.segmentation.data.SemanticSegmentationData","`",".","Examples","________","..","testsetup",":",":",">",">",">","from","PIL","import","Image",">",">",">","rand_image","=","Image.fromarray","(","np.random.randint","(","0",",","255",",","(","64",",","64",",","3",")",",","dtype=","''","uint8","''",")",")",">",">",">","_","=","[","rand_image.save","(","f","''","image_","{","i","}",".png","''",")","for","i","in","range","(","1",",","4",")","]",">",">",">","_","=","[","rand_image.save","(","f","''","predict_image_","{","i","}",".png","''",")","for","i","in","range","(","1",",","4",")","]","..","doctest",":",":",">",">",">","import","numpy","as","np",">",">",">","import","fiftyone","as","fo",">",">",">","from","flash","import","Trainer",">",">",">","from","flash.image","import","SemanticSegmentation",",","SemanticSegmentationData",">",">",">","train_dataset","=","fo.Dataset.from_images","(","...","[","``","image_1.png","''",",","``","image_2.png","''",",","``","image_3.png","''","]","...",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","<","BLANKLINE",">","...",">",">",">","samples","=","[","train_dataset","[","filepath","]","for","filepath","in","train_dataset.values","(","``","filepath","''",")","]",">",">",">","for","sample","in","samples",":","...","sample","[","``","ground_truth","''","]","=","fo.Segmentation","(","mask=np.random.randint","(","0",",","10",",","(","64",",","64",")",",","dtype=","''","uint8","''",")",")","...","sample.save","(",")","...",">",">",">","predict_dataset","=","fo.Dataset.from_images","(","...","[","``","predict_image_1.png","''",",","``","predict_image_2.png","''",",","``","predict_image_3.png","''","]","...",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","<","BLANKLINE",">","...",">",">",">","datamodule","=","SemanticSegmentationData.from_fiftyone","(","...","train_dataset=train_dataset",",","...","predict_dataset=predict_dataset",",","...","transform_kwargs=dict","(","image_size=","(","128",",","128",")",")",",","...","num_classes=10",",","...","batch_size=2",",","...",")",">",">",">","datamodule.num_classes","10",">",">",">","model","=","SemanticSegmentation","(","backbone=","''","resnet18","''",",","num_classes=datamodule.num_classes",")",">",">",">","trainer","=","Trainer","(","fast_dev_run=True",")",">",">",">","trainer.fit","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Training","...",">",">",">","trainer.predict","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Predicting","...","..","testcleanup",":",":",">",">",">","import","os",">",">",">","_","=","[","os.remove","(","f","''","image_","{","i","}",".png","''",")","for","i","in","range","(","1",",","4",")","]",">",">",">","_","=","[","os.remove","(","f","''","predict_image_","{","i","}",".png","''",")","for","i","in","range","(","1",",","4",")","]"]
code: def from_fiftyone(
      cls,
      train_dataset: Optional[SampleCollection] = None,
      val_dataset: Optional[SampleCollection] = None,
      test_dataset: Optional[SampleCollection] = None,
      predict_dataset: Optional[SampleCollection] = None,
      input_cls: Type[Input] = SemanticSegmentationFiftyOneInput,
      num_classes: Optional[int] = None,
      labels_map: Dict[int, Tuple[int, int, int]] = None,
      transform: INPUT_TRANSFORM_TYPE = SemanticSegmentationInputTransform,
      transform_kwargs: Optional[Dict] = None,
      label_field: str = "ground_truth",
      **data_module_kwargs: Any,
  ) -> "SemanticSegmentationData":
      """Load the :class:`~flash.image.segmentation.data.SemanticSegmentationData` from FiftyOne ``SampleCollection``
      objects.
  
      The supported file extensions are: ``.jpg``, ``.jpeg``, ``.png``, ``.ppm``, ``.bmp``, ``.pgm``, ``.tif``,
      ``.tiff``, ``.webp``, and ``.npy``.
      Mask image file paths will be extracted from the ``label_field`` in the ``SampleCollection`` objects.
      To learn how to customize the transforms applied for each stage, read our
      :ref:`customizing transforms guide <customizing_transforms>`.
  
      Args:
          train_dataset: The ``SampleCollection`` to use when training.
          val_dataset: The ``SampleCollection`` to use when validating.
          test_dataset: The ``SampleCollection`` to use when testing.
          predict_dataset: The ``SampleCollection`` to use when predicting.
          label_field: The field in the ``SampleCollection`` objects containing the targets.
          input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
          num_classes: The number of segmentation classes.
          labels_map: An optional mapping from class to RGB tuple indicating the colour to use when visualizing masks.
              If not provided, a random mapping will be used.
          transform: The :class:`~flash.core.data.io.input_transform.InputTransform` type to use.
          transform_kwargs: Dict of keyword arguments to be provided when instantiating the transforms.
          data_module_kwargs: Additional keyword arguments to provide to the
            :class:`~flash.core.data.data_module.DataModule` constructor.
  
      Returns:
          The constructed :class:`~flash.image.segmentation.data.SemanticSegmentationData`.
  
      Examples
      ________
  
      .. testsetup::
  
          >>> from PIL import Image
          >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
          >>> _ = [rand_image.save(f"image_{i}.png") for i in range(1, 4)]
          >>> _ = [rand_image.save(f"predict_image_{i}.png") for i in range(1, 4)]
  
      .. doctest::
  
          >>> import numpy as np
          >>> import fiftyone as fo
          >>> from flash import Trainer
          >>> from flash.image import SemanticSegmentation, SemanticSegmentationData
          >>> train_dataset = fo.Dataset.from_images(
          ...     ["image_1.png", "image_2.png", "image_3.png"]
          ... )  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          <BLANKLINE>
          ...
          >>> samples = [train_dataset[filepath] for filepath in train_dataset.values("filepath")]
          >>> for sample in samples:
          ...     sample["ground_truth"] = fo.Segmentation(mask=np.random.randint(0, 10, (64, 64), dtype="uint8"))
          ...     sample.save()
          ...
          >>> predict_dataset = fo.Dataset.from_images(
          ...     ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"]
          ... )  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          <BLANKLINE>
          ...
          >>> datamodule = SemanticSegmentationData.from_fiftyone(
          ...     train_dataset=train_dataset,
          ...     predict_dataset=predict_dataset,
          ...     transform_kwargs=dict(image_size=(128, 128)),
          ...     num_classes=10,
          ...     batch_size=2,
          ... )
          >>> datamodule.num_classes
          10
          >>> model = SemanticSegmentation(backbone="resnet18", num_classes=datamodule.num_classes)
          >>> trainer = Trainer(fast_dev_run=True)
          >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Training...
          >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Predicting...
  
      .. testcleanup::
  
          >>> import os
          >>> _ = [os.remove(f"image_{i}.png") for i in range(1, 4)]
          >>> _ = [os.remove(f"predict_image_{i}.png") for i in range(1, 4)]
  
      """
  
      return cls(
          input_cls(
              RunningStage.TRAINING,
              train_dataset,
              label_field=label_field,
              num_classes=num_classes,
              labels_map=labels_map,
          ),
          input_cls(
              RunningStage.VALIDATING,
              val_dataset,
              label_field=label_field,
              num_classes=num_classes,
              labels_map=labels_map,
          ),
          input_cls(
              RunningStage.TESTING,
              test_dataset,
              label_field=label_field,
              num_classes=num_classes,
              labels_map=labels_map,
          ),
          input_cls(RunningStage.PREDICTING, predict_dataset),
          transform=transform,
          transform_kwargs=transform_kwargs,
          **data_module_kwargs,
      )
  
imports: from typing import Any, Collection, Dict, Optional, Sequence, Tuple, Type
  import numpy
  from torch import Tensor
  from flash.core.data.callback import BaseDataFetcher
  from flash.core.data.data_module import DataModule
  from flash.core.data.io.input import Input
  from flash.core.utilities.imports import _FIFTYONE_AVAILABLE, _SEGMENTATION_MODELS_AVAILABLE, lazy_import
  from flash.core.utilities.stages import RunningStage
  from flash.core.utilities.types import INPUT_TRANSFORM_TYPE
  from flash.image.segmentation.input import SemanticSegmentationFiftyOneInput, SemanticSegmentationFilesInput, SemanticSegmentationFolderInput, SemanticSegmentationNumpyInput, SemanticSegmentationTensorInput
  from flash.image.segmentation.input_transform import SemanticSegmentationInputTransform
  from flash.image.segmentation.viz import SegmentationMatplotlibVisualization
label_desc: Use image node_id 6 for calling the SemanticSegmentationData obj's underlying member method code with example usage: obj.from_fiftyone(cls, train_dataset, val_dataset, test_dataset, predict_dataset, input_cls, num_classes, labels_map, transform, transform_kwargs, label_field) and returns: cls