o
    *jA
                     @   s   d dl Z d dlmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ ejejejd
G dd de
ZdS )    N)AnyDict)ndarray)Preprocessors)Preprocessor)PREPROCESSORS)Fields)read_config)type_assert)module_namec                       sB   e Zd Z fddZeeedejdee	ef fddZ
  ZS )#ImageClassificationMmcvPreprocessorc           
         s   ddl }ddlm} ddlm} t jd
i | d| _tj	
|d}tj	|r6|j|}d|j_d}nt|}d|jj_d}|dkrb|jjjd d d	krX|jjjd ||jjj| _dS |jjd d d	krs|jjd ||jj}	||	| _dS )a  Preprocess the image.

        What this preprocessor will do:
        1. Remove the `LoadImageFromFile` preprocessor(which will be called in the pipeline).
        2. Compose and instantiate other preprocessors configured in the file.
        3. Call the sub preprocessors one by one.

        This preprocessor supports two types of configuration:
        1. The mmcv config file, configured in a `config.py`
        2. The maas config file, configured in a `configuration.json`
        By default, if the `config.py` exists, the preprocessor will use the mmcv config file.

        Args:
            model_dir (str): The model dir to build the preprocessor from.
        r   N)Compose)preprocess_transformZ	ms_configz	config.pyZmmcv_configtypeZLoadImageFromFile )mmcvZmmcls.datasets.pipelinesr   Z/modelscope.models.cv.image_classification.utilsr   super__init__config_typeospathjoinexistsZConfigfromfilemodelZ
pretrainedr	   Zmm_modeldatatestZpipelinepoppreprocessorsZpreprocessorval)
selfZ	model_dirkwargsr   r   r   Z	mm_configcfgr   Zdata_pipeline	__class__r   o/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/preprocessors/cv/mmcls_preprocessor.pyr      s*   
z,ImageClassificationMmcvPreprocessor.__init__r   returnc                 C   s   t |d}| |}|S )N)Zimg)dictr   )r    r   r   r   r%   __call__@   s   

z,ImageClassificationMmcvPreprocessor.__call__)__name__
__module____qualname__r   r
   objectnpr   r   strr(   __classcell__r   r   r#   r%   r      s    +&r   )r   typingr   r   numpyr-   r   Zmodelscope.metainfor   Zmodelscope.preprocessors.baser   Z modelscope.preprocessors.builderr   Zmodelscope.utils.constantr   Zmodelscope.utils.hubr	   Zmodelscope.utils.type_assertr
   Zregister_moduleZcvZ&image_classification_mmcv_preprocessorr   r   r   r   r%   <module>   s   