
    #
3j 
                     b    S SK r S SKJr  S SKrS SKrS SKJr  S SKJr	  SSK
Jr   " S S\5      rg)    N)List)Image   )BaseSessionc                   V    \ rS rSrSrS rS\S\\   4S jr\	S 5       r
\	S 5       rS	rg
)BiRefNetSessionGeneral   zW
This class represents a BiRefNet-General session, which is a subclass of BaseSession.
c                 <    SS[         R                  " U* 5      -   -  $ )Nr   )npexp)selfmats     Y/home/wildlama/miniconda3/lib/python3.13/site-packages/rembg/sessions/birefnet_general.pysigmoidBiRefNetSessionGeneral.sigmoid   s    At$%%    imgreturnc           	         U R                   R                  SU R                  USSS5      5      nU R                  US   SS2SSS2SS24   5      n[        R
                  " U5      n[        R                  " U5      nXW-
  Xg-
  -  n[        R                  " U5      n[        R                  " US-  R                  S5      SS	9nUR                  UR                  [        R                  R                  5      nU/$ )
a
  
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      uint8L)mode)inner_sessionrun	normalizer   r   maxminsqueezer   	fromarrayastyperesizesize
ResamplingLANCZOS)	r   r   argskwargsort_outspredmamimasks	            r   predictBiRefNetSessionGeneral.predict   s     %%))NN*,A<
 ||HQK1a
34VVD\VVD\	bg&zz$s
227;#F{{388U%5%5%=%=>vr   c           
         U R                   " U0 UD6 S3n[        R                  " SU R                  " U0 UD6(       a  SOSUU R                  " U0 UD6SS9  [
        R                  R                  U R                  " U0 UD6U5      $ )z
Downloads the BiRefNet-General 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.onnxz]https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-general-epoch_244.onnxNz$md5:7a35a0141cbbc80de11d9c9a28f52697T)fnamepathprogressbar)namepoochretrievechecksum_disabled
u2net_homeosr2   join)clsr'   r(   r1   s       r   download_models&BiRefNetSessionGeneral.download_models4   s     88T,V,-U3k (($9&9 ;00
	
 ww||CNND;F;UCCr   c                     g)z
Returns the name of the BiRefNet-General session.

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

Returns:
    str: The name of the session.
zbirefnet-general )r;   r'   r(   s      r   r4   BiRefNetSessionGeneral.nameO   s     "r   r?   N)__name__
__module____qualname____firstlineno____doc__r   PILImager   r.   classmethodr<   r4   __static_attributes__r?   r   r   r   r      sN    &8 h @ D D4 " "r   r   )r9   typingr   numpyr   r5   PILr   	PIL.ImagerF   baser   r   r?   r   r   <module>rN      s(    	     ' O"[ O"r   