o
    ॵiA
                     @   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_transform	ms_configz	config.pymmcv_configtypeLoadImageFromFile )mmcvmmcls.datasets.pipelinesr   /modelscope.models.cv.image_classification.utilsr   super__init__config_typeospathjoinexistsConfigfromfilemodel
pretrainedr	   mm_modeldatatestpipelinepoppreprocessorspreprocessorval)
self	model_dirkwargsr   r   r   	mm_configcfgr   data_pipeline	__class__r   b/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/preprocessors/cv/mmcls_preprocessor.pyr      s*   
z,ImageClassificationMmcvPreprocessor.__init__r#   returnc                 C   s   t |d}| |}|S )N)img)dictr'   )r*   r#   r   r   r2   __call__@   s   

z,ImageClassificationMmcvPreprocessor.__call__)__name__
__module____qualname__r   r
   objectnpr   r   strr6   __classcell__r   r   r0   r2   r      s    +&r   )r   typingr   r   numpyr;   r   modelscope.metainfor   modelscope.preprocessors.baser    modelscope.preprocessors.builderr   modelscope.utils.constantr   modelscope.utils.hubr	   modelscope.utils.type_assertr
   register_modulecv&image_classification_mmcv_preprocessorr   r   r   r   r2   <module>   s   