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 )
BriaRmBgSessionz\
    This class represents a Bria-rmbg-2.0 session, which is a subclass of BaseSession.
    )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 )
aJ  
        Predicts the output masks for the input image using the inner session.

        Parameters:
            img (PILImage): The input image.
            *args: Additional positional arguments.
            **kwargs: Additional keyword arguments.

        Returns:
            List[PILImage]: The list of output 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   J/var/www/html/venv/lib/python3.8/site-packages/rembg/sessions/bria_rmbg.pypredict   s"        


zBriaRmBgSession.predictc                 O   sT   | j || d}tjd| j||r(dnd|| j||dd tj| j|||S )a!  
        Downloads the BRIA-RMBG 2.0 model file from a specific URL and saves it.

        Parameters:
            *args: Additional positional arguments.
            **kwargs: Additional keyword arguments.

        Returns:
            str: The path to the downloaded model file.
        z.onnxzPhttps://github.com/danielgatis/rembg/releases/download/v0.0.0/bria-rmbg-2.0.onnxNzGsha256:5b486f08200f513f460da46dd701db5fbb47d79b4be4b708a19444bcd4e79958T)fnamepathZprogressbar)namepoochretrieveZchecksum_disabledZ
u2net_homeosr   join)clsr   r   r   r   r   r   download_models1   s    

zBriaRmBgSession.download_modelsc                 O   s   dS )z
        Returns the name of the Bria-rmbg session.

        Parameters:
            *args: Additional positional arguments.
            **kwargs: Additional keyword arguments.

        Returns:
            str: The name of the session.
        z	bria-rmbgr   )r%   r   r   r   r   r   r    L   s    zBriaRmBgSession.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   