def _load_dataset_from_folder(
    root: str,
    transform: Callable[[Any], Any],
    is_valid_file: Callable[[str], bool] | None,
    tqdm_args: dict[str, Any] | None,
    num_workers_video_frame_counting: int = 0,
) -> datasets.VisionDataset:
    """Initializes a dataset from a folder.

    This function determines the appropriate dataset type based on the contents of the root directory
    and returns the corresponding dataset object.

    Args:
        root: Root directory path.
        transform: Composed image transformations to be applied to the dataset.
        is_valid_file: Optional function to determine valid files.
        tqdm_args: Optional dictionary of arguments for tqdm progress bar.
        num_workers_video_frame_counting: Number of workers for video frame counting.

    Returns:
        A dataset object (VideoDataset, ImageFolder, or DatasetFolder) based on the directory contents.

    Raises:
        ValueError: If the specified dataset directory doesn't exist or if videos are present
                but VideoDataset is not available.
    """
    if not os.path.exists(root):
        raise ValueError(f"The input directory {root} does not exist!")

    contains_videos = _contains_videos(root, VIDEO_EXTENSIONS)
    if contains_videos and not VIDEO_DATASET_AVAILABLE:
        raise ValueError(
            f"The input directory {root} contains videos "
            "but the VideoDataset is not available. "
            "Make sure you have installed the right "
            "dependencies. The error from the imported "
            f"module was: {VIDEO_DATASET_ERRORMSG}"
        )

    if contains_videos:
        return VideoDataset(
            root,
            extensions=VIDEO_EXTENSIONS,
            transform=transform,
            is_valid_file=is_valid_file,
            tqdm_args=tqdm_args,
            num_workers=num_workers_video_frame_counting,
        )
    elif _contains_subdirs(root):
        return datasets.ImageFolder(
            root, transform=transform, is_valid_file=is_valid_file
        )
    else:
        return DatasetFolder(
            root,
            extensions=IMG_EXTENSIONS,
            transform=transform,
            is_valid_file=is_valid_file,
        )
Initializes a dataset from a folder.

    This function determines the appropriate dataset type based on the contents of the root directory
    and returns the corresponding dataset object.

    Args:
        root: Root directory path.
        transform: Composed image transformations to be applied to the dataset.
        is_valid_file: Optional function to determine valid files.
        tqdm_args: Optional dictionary of arguments for tqdm progress bar.
        num_workers_video_frame_counting: Number of workers for video frame counting.

    Returns:
        A dataset object (VideoDataset, ImageFolder, or DatasetFolder) based on the directory contents.

    Raises:
        ValueError: If the specified dataset directory doesn't exist or if videos are present
                but VideoDataset is not available.
    
lightly/data/_helpers.py