U
    !?h
                     @   s\   d dl Z d dlmZ d dlZd dlZd dlmZ d dlmZ	 ddl
mZ G dd deZdS )    N)List)Image   )BaseSessionc                   @   s<   e Zd ZdZeee dddZedd Zedd Z	d	S )
SiluetaSessionz5This is a class representing a SiluetaSession object.)imgreturnc           	   	   O   s   | j d| |ddd}|d dddddddf }t|}t|}|| ||  }t|}tj|d 	ddd	}|
|jtjj}|gS )
a  
        Predict the mask of the input image.

        This method takes an image as input, preprocesses it, and performs a prediction to generate a mask. The generated mask is then post-processed and returned as a list of PILImage objects.

        Parameters:
            img (PILImage): The input image to be processed.
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            List[PILImage]: A list of post-processed masks.
        N)g
ףp=
?gv/?gCl?)gZd;O?gy&1?g?)@  r	   r      Zuint8L)mode)Zinner_sessionrun	normalizenpmaxminZsqueezer   Z	fromarrayZastyperesizesizeZ
ResamplingZLANCZOS)	selfr   argskwargsZort_outspredmamimask r   H/var/www/html/venv/lib/python3.8/site-packages/rembg/sessions/silueta.pypredict   s"        


zSiluetaSession.predictc                 O   sP   |    d}tjd| j||r$dnd|| j||dd tj| j|||S )ay  
        Download the pre-trained model file.

        This method downloads the pre-trained model file from a specified URL. The file is saved to the U2NET home directory.

        Parameters:
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            str: The path to the downloaded model file.
        z.onnxzJhttps://github.com/danielgatis/rembg/releases/download/v0.0.0/silueta.onnxNz$md5:55e59e0d8062d2f5d013f4725ee84782T)fnamepathZprogressbar)namepoochretrieveZchecksum_disabledZ
u2net_homeosr   join)clsr   r   r   r   r   r   download_models1   s    

zSiluetaSession.download_modelsc                 O   s   dS )a  
        Return the name of the model.

        This method returns the name of the Silueta model.

        Parameters:
            *args: Variable length argument list.
            **kwargs: Arbitrary keyword arguments.

        Returns:
            str: The name of the model.
        Zsiluetar   )r%   r   r   r   r   r   r    N   s    zSiluetaSession.nameN)
__name__
__module____qualname____doc__PILImager   r   classmethodr&   r    r   r   r   r   r      s   "
r   )r#   typingr   numpyr   r!   ZPILr   Z	PIL.Imager+   baser   r   r   r   r   r   <module>   s   