
    9i                     `    S r SSKrSSKrSSKJr  SSKrS rS rS rS r\	S:X  a  \" 5         gg)	z
Created by Jaided AI
Released Date: 19/08/2022
Description:
A wrapper for DCN operator for DBNet. This script is called inside the setup.py
of EasyOCR. It can also be called as a standalone script to compile the operator
manually.
    N)datetimec                 6   [        U [        5      (       d  U /n U  Vs/ s H+  n[        U[        5      (       a  UOUR                  S5      PM-     n nSn[	        S5        [        US5       nUR                  [        R                  " 5       R                  S5      S-   R                  S5      5        UR                  SR                  S5      5        UR                  SR                  S5      5        U  Vs/ s H  o$R                  U5      PM       nS S S 5        [	        S	R                  [        R                  R                  U5      5      5        [	        S
5        [	        S5        [	        SR                  U5      5        g s  snf s  snf ! , (       d  f       N= f)Nutf-8z=https://github.com/JaidedAI/EasyOCR/tree/master/easyocr/DBNetz)Failed to compile dcn operator for DBNet.wb%H:%M:%S - %d %b %Y
zCFailed to compile dcn operator for DBNet with the following error.
z+##########################################
z!Error message can be found in {}.z*##########################################z=EasyOCR can still be used with CRAFT text detector (default).z_To use DBNet text detector, please check {} for troubleshoot and compile dcn operator manually.)
isinstancelistbytesencodeprintopenwriter   nowstrftimeformatospathabspath)errorslog_patherrorurlfids        a/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/easyocr/scripts/compile_dbnet_dcn.pyprint_errorr      s9   fd##X^_X^uz%//eU\\'5JJX^F_
IC	
56	h			8<<>**+@ADHPPQXYZ		X__`ghi		=((12'-.ve5	v.	 

 

-
4
4RWW__X5N
OP	&M	
IJ	
k
r
rsv
wx ` 	/	 
	s$   2F *B
F
4FF
F


Fc                 6   [        US5       nUR                  [        R                  " 5       R	                  S5      S-   R                  S5      5        UR                  U S-   R                  S5      5        S S S 5        [        U 5        g ! , (       d  f       N= f)Nr   r   r   r   )r   r   r   r   r   r   r   )textr   r   s      r   print_successr      so    	h			8<<>**+@ADHPPQXYZ		4$;&&w/0 
 
$K 
	s   A)B


Bc                    [         R                  R                  U SSSS5      nUS:X  a  [        R                  " [         R                  R                  US5      5      n[        R                  " [         R                  R                  US5      5      nSR	                  [         R                  R                  [         R                  R                  U S5      5      5      n[        Xa5        U=(       a    U$ US	:X  a  [        R                  " [         R                  R                  US
5      5      n[        R                  " [         R                  R                  US5      5      nSR	                  [         R                  R                  [         R                  R                  U S5      5      5      n[        Xa5        U=(       a    U$ [        S5      e)NDBNetassetsopsdcncpuzdeform_conv_cpu.*.sozdeform_pool_cpu.*.soz0DCN CPU operator is compiled successfully at {}.cudazdeform_conv_cuda.*.sozdeform_pool_cuda.*.soz1DCN CUDA operator is compiled successfully at {}.z,'cpu_or_cuda' must be either 'cpu' or 'cuda')r   r   joinglobr   r   r   
ValueError)	
parent_dirr   cpu_or_cudadcn_dirconv_cpu_existpool_cpu_existsuccess_messageconv_cuda_existpool_cuda_exists	            r   validate_compilationr2   $   sd   ggll:w%GGe277<<9O#PQ277<<9O#PQLSSTVT[T[TcTcdfdkdkdpdpq{  }D  eE  UF  Go00.0		))BGGLL:Q$RS))BGGLL:Q$RSMTTUWU\U\UdUdegeleleqeqr|  ~E  fF  VG  Ho02?2GHH    c            	      8   [         R                  " 5       n [         R                  R                  [         R                  R                  [         R                  R	                  [
        5      5      5      n[         R                  R                  USS5      n [        S5        [         R                  " [         R                  R                  USSSS5      5        [        R                  " SSSS	9nUR                  S
:X  a  [         R                  " [         R                  R                  US5      5        [        XS5      (       a  [        R                  " SSSS	9n[        XS5      (       a  [        R                  " SSSS	9nO8[        UR                  5        [        UR                  UR                   /U5         [         R                  " U 5        g ! ["         a%  n[        SR%                  U5      U5         S nANAS nAff = f! [         R                  " U 5        f = f)Nr!   zlog.txtzCompiling DCN operators...r"   r#   r$   z#python setup.py build_ext --inplaceT)shellcapture_outputr   r%   ztouch dcn_cpu_compiling_successr&   z touch dcn_cuda_compiling_successz{})r   getcwdr   dirnamer   __file__r'   r   chdir
subprocessrun
returncoder2   __dict__r   stdoutstderr	Exceptionr   )cwdr*   r   resultr   s        r   mainrD   6   sp   
))+C1J!KLJww||Jw	:H*+
j%FG1PT
 !HHRWW\\*g67#J%@@#5TTX $J&AA#6dUY &//"6A 	  2DKK&112 	s=   C*G ?H  7G 7H 
G>G94H 9G>>H H__main__)
__doc__r   r(   r   r;   r   r   r2   rD   __name__ r3   r   <module>rI      sB    
   y I$8 zF r3   