zensvi.cv.Segmenter =================== .. py:class:: zensvi.cv.Segmenter(dataset='cityscapes', task='semantic', device=None, verbosity=1) A class for performing semantic and panoptic segmentation on images. The models used are from the Mask2Former (https://huggingface.co/docs/transformers/model_doc/mask2former). .. attribute:: device The device to run the model on (e.g., "cuda" or "cpu"). :type: str .. attribute:: dataset The name of the dataset (e.g., "cityscapes" or "mapillary"). :type: str .. attribute:: task The type of segmentation task (e.g., "semantic" or "panoptic"). :type: str .. attribute:: model_name The name of the pre-trained model corresponding to the dataset and task. :type: str .. attribute:: model The segmentation model. .. attribute:: processor The image processor for the model. .. attribute:: color_map A mapping of class IDs to colors. .. attribute:: label_map A mapping of class IDs to labels. .. attribute:: id_to_name_map A mapping of label IDs to label names. .. attribute:: verbosity Level of verbosity for progress bars (0=no progress, 1=outer loops only, 2=all loops) :type: int :param dataset: The name of the dataset (default is "cityscapes"). :type dataset: str :param task: The type of task (default is "semantic"). :type task: str :param device: The device to run the model on (e.g., "cuda" or "cpu"). If None, the default device will be used. :type device: str, optional :param verbosity: Level of verbosity for progress bars (0=no progress, 1=outer loops only, 2=all loops). Default is 1. :type verbosity: int, optional :returns: None .. py:method:: segment(dir_input: Union[str, pathlib.Path], dir_image_output: Union[str, pathlib.Path, None] = None, dir_summary_output: Union[str, pathlib.Path, None] = None, batch_size=1, save_image_options='segmented_image blend_image', save_format='json csv', csv_format='long', max_workers: Union[int, None] = None) Processes a batch of images for segmentation, saves the segmented images and summary statistics. This method handles the processing of images for segmentation, managing input/output directories, saving options, and parallel processing settings. The method requires specifying an input directory or a path to a single image and supports optional saving of output images and segmentation summaries. :param dir_input: Input directory or path to a single image file :param dir_image_output: Output directory where segmented images are saved :param dir_summary_output: Output directory where segmentation summary files are saved :param batch_size: Batch size for processing images (Default: 1) :param save_image_options: Options for saving images ("segmented_image blend_image") :param save_format: Format for saving summary files ("json csv") :param csv_format: Format for CSV summary files ("long" or "wide") :param max_workers: Maximum number of workers for parallel processing :returns: The method does not return any value but saves the processed results to specified directories. :rtype: None :raises ValueError: If neither dir_image_output nor dir_summary_output is provided :raises ValueError: If the input path is neither a file nor a directory .. py:method:: calculate_pixel_ratio_post_process(dir_input, dir_output, save_format='json csv') Calculates the pixel ratio of different classes present in the segmented images and saves the results in either JSON or CSV format. :param dir_input: A string or Path object representing the input directory containing the segmented images. :param dir_output: A string or Path object representing the output directory where the pixel ratio results will be saved. :param save_format: A list containing the file formats in which the results will be saved. The allowed file formats are "json" and "csv". The default value is "json csv". :returns: None