
    9ih                         S SK r S SKJrJr  S SKJr  SSKJr  SSKJ	r	J
r
Jr  SSK7  SSKJr  S	S
KJr  S\SS4S jr " S S\\S9rg)    N)ABCabstractmethod)Path   )AttrDict)check_supported_deviceset_env_for_deviceupdate_device_num)*)AutoRegisterABCMetaClass   )build_modelconfigreturnBaseEvaluatorc                     U R                   R                  n  [        R	                  U5      " U 5      $ ! [         a     N'f = f)zbuild model evaluator

Args:
    config (AttrDict): PaddleX pipeline config, which is loaded from pipeline yaml file.

Returns:
    BaseEvaluator: the evaluator, which is subclass of BaseEvaluator.
)GlobalmodelModuleNotFoundErrorr   get)r   
model_names     ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/modules/base/evaluator.pybuild_evaluatorr      sG     $$J Z(00  s   
A Ac                      ^  \ rS rSrSrSrU 4S jrS rS\S\	4S jr
S\4S	 jrSS
 jrSS\S\4S jjr\S 5       r\S 5       rSrU =r$ )r   /   zBase Model EvaluatorTc                   > [         TU ]  5         UR                  U l        UR                  U l        U R                  U R
                  R                  5      nU R
                  R                  SS5      (       a  U R
                  R                  SS5      n[        U R                  R                  US9u  U l        U l        g)zzInitialize the instance.

Args:
    config (AttrDict):  PaddleX pipeline config, which is loaded from pipeline yaml file.
basic_config_pathN)config_path)super__init__r   global_configEvaluateeval_configget_config_pathweight_pathr   r   r   
pdx_config	pdx_model)selfr   r   	__class__s      r   r    BaseEvaluator.__init__4   s     	#]]!??**4+;+;+G+GH 3T::**../BDIK*5$$++
'    c                     [        U5      R                  S-  nUR                  5       (       d  UR                  R                  S-  nUR                  5       (       d  [        SU SU S35        SnU$ )z
get config path

Args:
    weight_path (str): The path to the weight

Returns:
    config_path (str): The path to the config

config.yamlzThe config file (`z`) related to weight file (`z)`) does not exist. Using default instead.N)r   parentexistswarning)r(   r%   r   s      r   r$   BaseEvaluator.get_config_pathF   s}     ;'..>!!##%,,33mCK!!##$[M1Mk]  [D  E Kr+   metricsr   c                     [        U[        5      (       d  gU H$  nX   n[        U[        [        45      (       a  M$    g   g)zcheck evaluation metrics

Args:
    metrics (dict): evaluation output metrics

Returns:
    bool: whether the format of evaluation metrics is legal
FT)
isinstancedictfloatint)r(   r2   metricvals       r   check_returnBaseEvaluator.check_return]   s>     '4((F/CcE3<00  r+   c                 "   U R                  5         U R                  R                  " S0 U R                  5       D6nUR                  S:X  d   SUR                   S35       eUR
                  nU R                  U5      (       d   SU S35       eSU0$ )zDexecute model evaluating

Returns:
    dict: the evaluation metrics
r   z Encountered an unexpected error(z) in evaling!zThe return value(z!) of Evaluator.eval() is illegal!r2    )update_configr'   evaluateget_eval_kwargs
returncoder2   r:   )r(   evaluate_resultr2   s      r   r?   BaseEvaluator.evaluaten   s     	..11KD4H4H4JK&&!+	
-o.H.H-I J	 
	
+ "))  
 
 	Jwi'HI	J 
 7##r+   c                     Uc4  [         R                  R                  U R                  R                  S5      nU R
                  R                  U5        g)zdump the config

Args:
    config_file_path (str, optional): the path to save dumped config.
        Defaults to None, means that save in `Global.output` as `config.yaml`.
Nr-   )ospathjoinr!   outputr&   dump)r(   config_file_paths     r   dump_configBaseEvaluator.dump_config   s>     #!ww||D,>,>,E,E}U-.r+   using_device_numberc                 J   [        U R                  R                  U R                  R                  5        [	        U R                  R                  5        U(       a   [        U R                  R                  U5      OU R                  R                  nUR                  SS5      nU$ )zget device setting from config

Args:
    using_device_number (int, optional): specify device number to use.
        Defaults to None, means that base on config setting.

Returns:
    str: device setting, such as: `gpu:0,1`, `npu:0,1`, `cpu`.
dcugpu)r   r!   devicer   r	   r
   replace)r(   rM   device_settings      r   
get_deviceBaseEvaluator.get_device   s     	t1188$:L:L:R:RS4--445 # d00779LM##** 	 (//u=r+   c                     [         e)zupdate evaluation configNotImplementedErrorr(   s    r   r>   BaseEvaluator.update_config   
     "!r+   c                     [         e)z4get key-value arguments of model evaluation functionrW   rY   s    r   r@   BaseEvaluator.get_eval_kwargs   r[   r+   )r#   r!   r&   r'   )N)__name__
__module____qualname____firstlineno____doc___BaseEvaluator__is_baser    r$   r5   boolr:   r?   rK   r7   strrT   r   r>   r@   __static_attributes____classcell__)r)   s   @r   r   r   /   st    I
$.D T "$$ $(	/c S * " " " "r+   )	metaclass)rE   abcr   r   pathlibr   utils.configr   utils.devicer   r	   r
   utils.logging
utils.miscr   r   r   r   r=   r+   r   <module>ro      sL    
 #  $ 
  2 $1H 1 1"{"C#; {"r+   