class_docstr: The ``ImageClassificationData`` class is a :class:`~flash.core.data.data_module.DataModule` with a set of
  classmethods for loading data for image classification.
docstr: Load the :class:`~flash.image.classification.data.ImageClassificationData` from CSV files containing image
  file paths and their corresponding targets.
  
  Input images will be extracted from the ``input_field`` column in the CSV files.
  The supported file extensions are: ``.jpg``, ``.jpeg``, ``.png``, ``.ppm``, ``.bmp``, ``.pgm``, ``.tif``,
  ``.tiff``, ``.webp``, and ``.npy``.
  The targets will be extracted from the ``target_fields`` in the CSV files and can be in any of our
  :ref:`supported classification target formats <formatting_classification_targets>`.
  To learn how to customize the transforms applied for each stage, read our
  :ref:`customizing transforms guide <customizing_transforms>`.
  
  Args:
      input_field: The field (column name) in the CSV files containing the image file paths.
      target_fields: The field (column name) or list of fields in the CSV files containing the targets.
      train_file: The CSV file to use when training.
      train_images_root: The root directory containing train images.
      train_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
          file path.
      val_file: The CSV file to use when validating.
      val_images_root: The root directory containing validation images.
      val_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
          file path.
      test_file: The CSV file to use when testing.
      test_images_root: The root directory containing test images.
      test_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
          file path.
      predict_file: The CSV file to use when predicting.
      predict_images_root: The root directory containing predict images.
      predict_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an
          image file path.
      target_formatter: Optionally provide a :class:`~flash.core.data.utilities.classification.TargetFormatter` to
          control how targets are handled. See :ref:`formatting_classification_targets` for more details.
      input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
      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.classification.data.ImageClassificationData`.
  
  Examples
  ________
  
  The files can be in Comma Separated Values (CSV) format with either a ``.csv`` or ``.txt`` extension.
  
  .. testsetup::
  
      >>> import os
      >>> from PIL import Image
      >>> from pandas import DataFrame
      >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
      >>> os.makedirs("train_folder", exist_ok=True)
      >>> os.makedirs("predict_folder", exist_ok=True)
      >>> _ = [rand_image.save(os.path.join("train_folder", f"image_{i}.png")) for i in range(1, 4)]
      >>> _ = [rand_image.save(os.path.join("predict_folder", f"predict_image_{i}.png")) for i in range(1, 4)]
      >>> DataFrame.from_dict({
      ...     "images": ["image_1.png", "image_2.png", "image_3.png"],
      ...     "targets": ["cat", "dog", "cat"],
      ... }).to_csv("train_data.csv", index=False)
      >>> DataFrame.from_dict({
      ...     "images": ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"],
      ... }).to_csv("predict_data.csv", index=False)
  
  The file ``train_data.csv`` contains the following:
  
  .. code-block::
  
      images,targets
      image_1.png,cat
      image_2.png,dog
      image_3.png,cat
  
  The file ``predict_data.csv`` contains the following:
  
  .. code-block::
  
      images
      predict_image_1.png
      predict_image_2.png
      predict_image_3.png
  
  .. doctest::
  
      >>> from flash import Trainer
      >>> from flash.image import ImageClassifier, ImageClassificationData
      >>> datamodule = ImageClassificationData.from_csv(
      ...     "images",
      ...     "targets",
      ...     train_file="train_data.csv",
      ...     train_images_root="train_folder",
      ...     predict_file="predict_data.csv",
      ...     predict_images_root="predict_folder",
      ...     transform_kwargs=dict(image_size=(128, 128)),
      ...     batch_size=2,
      ... )
      >>> datamodule.num_classes
      2
      >>> datamodule.labels
      ['cat', 'dog']
      >>> model = ImageClassifier(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 shutil
      >>> shutil.rmtree("train_folder")
      >>> shutil.rmtree("predict_folder")
      >>> os.remove("train_data.csv")
      >>> os.remove("predict_data.csv")
  
  Alternatively, the files can be in Tab Separated Values (TSV) format with a ``.tsv`` extension.
  
  .. testsetup::
  
      >>> import os
      >>> from PIL import Image
      >>> from pandas import DataFrame
      >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
      >>> os.makedirs("train_folder", exist_ok=True)
      >>> os.makedirs("predict_folder", exist_ok=True)
      >>> _ = [rand_image.save(os.path.join("train_folder", f"image_{i}.png")) for i in range(1, 4)]
      >>> _ = [rand_image.save(os.path.join("predict_folder", f"predict_image_{i}.png")) for i in range(1, 4)]
      >>> DataFrame.from_dict({
      ...     "images": ["image_1.png", "image_2.png", "image_3.png"],
      ...     "targets": ["cat", "dog", "cat"],
      ... }).to_csv("train_data.tsv", sep="\t", index=False)
      >>> DataFrame.from_dict({
      ...     "images": ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"],
      ... }).to_csv("predict_data.tsv", sep="\t", index=False)
  
  The file ``train_data.tsv`` contains the following:
  
  .. code-block::
  
      images      targets
      image_1.png cat
      image_2.png dog
      image_3.png cat
  
  The file ``predict_data.tsv`` contains the following:
  
  .. code-block::
  
      images
      predict_image_1.png
      predict_image_2.png
      predict_image_3.png
  
  .. doctest::
  
      >>> from flash import Trainer
      >>> from flash.image import ImageClassifier, ImageClassificationData
      >>> datamodule = ImageClassificationData.from_csv(
      ...     "images",
      ...     "targets",
      ...     train_file="train_data.tsv",
      ...     train_images_root="train_folder",
      ...     predict_file="predict_data.tsv",
      ...     predict_images_root="predict_folder",
      ...     transform_kwargs=dict(image_size=(128, 128)),
      ...     batch_size=2,
      ... )
      >>> datamodule.num_classes
      2
      >>> datamodule.labels
      ['cat', 'dog']
      >>> model = ImageClassifier(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 shutil
      >>> shutil.rmtree("train_folder")
      >>> shutil.rmtree("predict_folder")
      >>> os.remove("train_data.tsv")
      >>> os.remove("predict_data.tsv")
code: def from_csv(
      cls,
      input_field: str,
      target_fields: Optional[Union[str, List[str]]] = None,
      train_file: Optional[PATH_TYPE] = None,
      train_images_root: Optional[PATH_TYPE] = None,
      train_resolver: Optional[
          Callable[[PATH_TYPE, Any], PATH_TYPE]
      ] = None,
      val_file: Optional[PATH_TYPE] = None,
      val_images_root: Optional[PATH_TYPE] = None,
      val_resolver: Optional[
          Callable[[PATH_TYPE, Any], PATH_TYPE]
      ] = None,
      test_file: Optional[str] = None,
      test_images_root: Optional[str] = None,
      test_resolver: Optional[
          Callable[[PATH_TYPE, Any], PATH_TYPE]
      ] = None,
      predict_file: Optional[str] = None,
      predict_images_root: Optional[str] = None,
      predict_resolver: Optional[
          Callable[[PATH_TYPE, Any], PATH_TYPE]
      ] = None,
      target_formatter: Optional[TargetFormatter] = None,
      input_cls: Type[Input] = ImageClassificationCSVInput,
      transform: INPUT_TRANSFORM_TYPE = ImageClassificationInputTransform,
      transform_kwargs: Optional[Dict] = None,
      **data_module_kwargs: Any,
  ) -> "ImageClassificationData":
      """Load the :class:`~flash.image.classification.data.ImageClassificationData` from CSV files containing image
      file paths and their corresponding targets.
  
      Input images will be extracted from the ``input_field`` column in the CSV files.
      The supported file extensions are: ``.jpg``, ``.jpeg``, ``.png``, ``.ppm``, ``.bmp``, ``.pgm``, ``.tif``,
      ``.tiff``, ``.webp``, and ``.npy``.
      The targets will be extracted from the ``target_fields`` in the CSV files and can be in any of our
      :ref:`supported classification target formats <formatting_classification_targets>`.
      To learn how to customize the transforms applied for each stage, read our
      :ref:`customizing transforms guide <customizing_transforms>`.
  
      Args:
          input_field: The field (column name) in the CSV files containing the image file paths.
          target_fields: The field (column name) or list of fields in the CSV files containing the targets.
          train_file: The CSV file to use when training.
          train_images_root: The root directory containing train images.
          train_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
              file path.
          val_file: The CSV file to use when validating.
          val_images_root: The root directory containing validation images.
          val_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
              file path.
          test_file: The CSV file to use when testing.
          test_images_root: The root directory containing test images.
          test_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an image
              file path.
          predict_file: The CSV file to use when predicting.
          predict_images_root: The root directory containing predict images.
          predict_resolver: Optionally provide a function which converts an entry from the ``input_field`` into an
              image file path.
          target_formatter: Optionally provide a :class:`~flash.core.data.utilities.classification.TargetFormatter` to
              control how targets are handled. See :ref:`formatting_classification_targets` for more details.
          input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
          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.classification.data.ImageClassificationData`.
  
      Examples
      ________
  
      The files can be in Comma Separated Values (CSV) format with either a ``.csv`` or ``.txt`` extension.
  
      .. testsetup::
  
          >>> import os
          >>> from PIL import Image
          >>> from pandas import DataFrame
          >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
          >>> os.makedirs("train_folder", exist_ok=True)
          >>> os.makedirs("predict_folder", exist_ok=True)
          >>> _ = [rand_image.save(os.path.join("train_folder", f"image_{i}.png")) for i in range(1, 4)]
          >>> _ = [rand_image.save(os.path.join("predict_folder", f"predict_image_{i}.png")) for i in range(1, 4)]
          >>> DataFrame.from_dict({
          ...     "images": ["image_1.png", "image_2.png", "image_3.png"],
          ...     "targets": ["cat", "dog", "cat"],
          ... }).to_csv("train_data.csv", index=False)
          >>> DataFrame.from_dict({
          ...     "images": ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"],
          ... }).to_csv("predict_data.csv", index=False)
  
      The file ``train_data.csv`` contains the following:
  
      .. code-block::
  
          images,targets
          image_1.png,cat
          image_2.png,dog
          image_3.png,cat
  
      The file ``predict_data.csv`` contains the following:
  
      .. code-block::
  
          images
          predict_image_1.png
          predict_image_2.png
          predict_image_3.png
  
      .. doctest::
  
          >>> from flash import Trainer
          >>> from flash.image import ImageClassifier, ImageClassificationData
          >>> datamodule = ImageClassificationData.from_csv(
          ...     "images",
          ...     "targets",
          ...     train_file="train_data.csv",
          ...     train_images_root="train_folder",
          ...     predict_file="predict_data.csv",
          ...     predict_images_root="predict_folder",
          ...     transform_kwargs=dict(image_size=(128, 128)),
          ...     batch_size=2,
          ... )
          >>> datamodule.num_classes
          2
          >>> datamodule.labels
          ['cat', 'dog']
          >>> model = ImageClassifier(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 shutil
          >>> shutil.rmtree("train_folder")
          >>> shutil.rmtree("predict_folder")
          >>> os.remove("train_data.csv")
          >>> os.remove("predict_data.csv")
  
      Alternatively, the files can be in Tab Separated Values (TSV) format with a ``.tsv`` extension.
  
      .. testsetup::
  
          >>> import os
          >>> from PIL import Image
          >>> from pandas import DataFrame
          >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8"))
          >>> os.makedirs("train_folder", exist_ok=True)
          >>> os.makedirs("predict_folder", exist_ok=True)
          >>> _ = [rand_image.save(os.path.join("train_folder", f"image_{i}.png")) for i in range(1, 4)]
          >>> _ = [rand_image.save(os.path.join("predict_folder", f"predict_image_{i}.png")) for i in range(1, 4)]
          >>> DataFrame.from_dict({
          ...     "images": ["image_1.png", "image_2.png", "image_3.png"],
          ...     "targets": ["cat", "dog", "cat"],
          ... }).to_csv("train_data.tsv", sep="\\t", index=False)
          >>> DataFrame.from_dict({
          ...     "images": ["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"],
          ... }).to_csv("predict_data.tsv", sep="\\t", index=False)
  
      The file ``train_data.tsv`` contains the following:
  
      .. code-block::
  
          images      targets
          image_1.png cat
          image_2.png dog
          image_3.png cat
  
      The file ``predict_data.tsv`` contains the following:
  
      .. code-block::
  
          images
          predict_image_1.png
          predict_image_2.png
          predict_image_3.png
  
      .. doctest::
  
          >>> from flash import Trainer
          >>> from flash.image import ImageClassifier, ImageClassificationData
          >>> datamodule = ImageClassificationData.from_csv(
          ...     "images",
          ...     "targets",
          ...     train_file="train_data.tsv",
          ...     train_images_root="train_folder",
          ...     predict_file="predict_data.tsv",
          ...     predict_images_root="predict_folder",
          ...     transform_kwargs=dict(image_size=(128, 128)),
          ...     batch_size=2,
          ... )
          >>> datamodule.num_classes
          2
          >>> datamodule.labels
          ['cat', 'dog']
          >>> model = ImageClassifier(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 shutil
          >>> shutil.rmtree("train_folder")
          >>> shutil.rmtree("predict_folder")
          >>> os.remove("train_data.tsv")
          >>> os.remove("predict_data.tsv")
  
      """
      ds_kw = {
          "target_formatter": target_formatter,
      }
  
      train_data = (
          train_file,
          input_field,
          target_fields,
          train_images_root,
          train_resolver,
      )
      val_data = (
          val_file,
          input_field,
          target_fields,
          val_images_root,
          val_resolver,
      )
      test_data = (
          test_file,
          input_field,
          target_fields,
          test_images_root,
          test_resolver,
      )
      predict_data = (
          predict_file,
          input_field,
          None,
          predict_images_root,
          predict_resolver,
      )
  
      train_input = input_cls(
          RunningStage.TRAINING, *train_data, **ds_kw
      )
      ds_kw["target_formatter"] = getattr(
          train_input, "target_formatter", None
      )
  
      return cls(
          train_input,
          input_cls(RunningStage.VALIDATING, *val_data, **ds_kw),
          input_cls(RunningStage.TESTING, *test_data, **ds_kw),
          input_cls(RunningStage.PREDICTING, *predict_data, **ds_kw),
          transform=transform,
          transform_kwargs=transform_kwargs,
          **data_module_kwargs,
      )
  
imports: from typing import Any, Callable, Collection, Dict, List, Optional, Sequence, Tuple, Type, Union
  import numpy
  import pandas
  from torch import Tensor
  from torch.utils.data import Dataset
  from flash.core.data.base_viz import BaseVisualization
  from flash.core.data.callback import BaseDataFetcher
  from flash.core.data.data_module import DataModule, DatasetInput
  from flash.core.data.io.input import DataKeys, Input
  from flash.core.data.io.input_transform import INPUT_TRANSFORM_TYPE
  from flash.core.data.utilities.classification import TargetFormatter
  from flash.core.data.utilities.paths import PATH_TYPE
  from flash.core.integrations.labelstudio.input import LabelStudioImageClassificationInput, _parse_labelstudio_arguments
  from flash.core.utilities.imports import _FIFTYONE_AVAILABLE, _MATPLOTLIB_AVAILABLE, _TOPIC_IMAGE_AVAILABLE, Image, requires
  from flash.core.utilities.stages import RunningStage
  from flash.image.classification.input import ImageClassificationCSVInput, ImageClassificationDataFrameInput, ImageClassificationFiftyOneInput, ImageClassificationFilesInput, ImageClassificationFolderInput, ImageClassificationImageInput, ImageClassificationNumpyInput, ImageClassificationTensorInput
  from flash.image.classification.input_transform import ImageClassificationInputTransform
label_desc: Use image node_id 7 for calling the ImageClassificationData obj's underlying member method code with example usage: obj.from_csv(cls, input_field, target_fields, train_file, train_images_root, train_resolver, val_file, val_images_root, val_resolver, test_file, test_images_root, test_resolver, predict_file, predict_images_root, predict_resolver, target_formatter, input_cls, transform, transform_kwargs) and returns: cls