o
    oi                     @  sp   d dl mZ d dlmZmZ d dlmZ d dlZd dlm	Z	m
Z
 d dlmZ ddlmZ d	gZG d
d	 d	ZdS )    )annotations)AnyOptional)nnN)Moduletensor)segmentation_models_pytorch   )SemanticSegmentationSegmentationModelsBuilderc                   @  s6   e Zd Ze						ddddZedddZdS )r   Unetresnet34imagenet   r	   softmax
model_namestrencoder_nameencoder_weightsOptional[str]in_channelsintclasses
activationkwargsr   returnr
   c           
      K  sT   t j|}t|}tt | d|||||d|}	t|	|t |  d| dS )a3  SegmentationModel is a module that wraps a segmentation model.

        This module uses SegmentationModel library for segmentation.

        Args:
            model_name: Name of the model to use. Valid options are:
                "Unet", "UnetPlusPlus", "MAnet", "LinkNet", "FPN", "PSPNet", "PAN", "DeepLabV3", "DeepLabV3Plus".
            encoder_name: Name of the encoder to use.
            encoder_depth: Depth of the encoder.
            encoder_weights: Weights of the encoder.
            decoder_channels: Number of channels in the decoder.
            in_channels: Number of channels in the input.
            classes: Number of classes to predict.
            activation: Type of activation layer.
            **kwargs: Additional arguments to pass to the model. Detailed arguments can be found at:
                https://github.com/qubvel-org/segmentation_models.pytorch/tree/main/segmentation_models_pytorch/decoders

        Note:
            Only encoder weights are available.
            Pretrained weights for the whole model are not available.

        )r   r   r   r   r   _)modelpre_processorpost_processornameN )	smpencodersget_preprocessing_paramsr   get_preprocessing_pipelinegetattrr
   r   Identity)
r   r   r   r   r   r   r   preproc_paramspreprocessorsegmentation_modelr!   r!   b/home/ubuntu/.local/lib/python3.10/site-packages/kornia/models/segmentation/segmentation_models.pybuild"   s"    

	zSegmentationModelsBuilder.buildr(   dict[str, Any]-kornia.augmentation.container.ImageSequentialc                 C  s   g }| d }|dkr| tj  n|dkrntd| | d }|d dkr5| tjjdd	d
 n|d dkr<ntd| | d d urQt| d g}ntd}| d d urct| d g}ntd}| tjj||d
 tjj	j
| S )Ninput_spaceBGRRGBzUnsupported input space: input_ranger	      g        gp?)meanstdzUnsupported input range: r4   r5   g      ?)appendkorniacolorBgrToRgb
ValueErrorenhance	Normalizer   augmentation	containerImageSequential)r(   proc_sequencer/   r2   r4   r5   r!   r!   r+   r%   T   s*   z4SegmentationModelsBuilder.get_preprocessing_pipelineN)r   r   r   r   r	   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   )r(   r-   r   r.   )__name__
__module____qualname__staticmethodr,   r%   r!   r!   r!   r+   r   !   s    1)
__future__r   typingr   r   torchr   r7   kornia.corer   r   kornia.core.externalr   r"   baser
   __all__r   r!   r!   r!   r+   <module>   s   