o
    ߥi                     @   sz   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 e	jejejd	G d
d deZdS )    )AnyDictN)Models)
TorchModel)MODELS)Tasks   )VisionEfficientTuning)module_namec                       sH   e Zd ZdZdef fddZdeeef deeef fddZ  Z	S )	VisionEfficientTuningModela   The implementation of vision efficient tuning model based on TorchModel.

    This model is constructed with the following parts:
        - 'backbone': pre-trained backbone model with parameters.
        - 'head': classification head with fine-tuning.
    	model_dirc                    sV   t  | tdd|i|| _| jj| _ttj rdnd| _| j	| j dS )a   Initialize a vision efficient tuning model.

        Args:
          model_dir: model id or path, where model_dir/pytorch_model.pt contains:
                    - 'backbone_weight': parameters of backbone.
                    - 'head_weight': parameters of head.
        r   cudacpuN )
super__init__r	   modelCLASSEStorchdevicer   is_availableto)selfr   kwargs	__class__r   f/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/cv/vision_efficient_tuning/model.pyr      s   
z#VisionEfficientTuningModel.__init__inputreturnc                 C   s   | j di |}|S )z Dynamic forward function of vision efficient tuning model.

        Args:
            input: the input data dict contanis:
                - imgs: (B, 3, H, W).
                - labels: (B), when training stage.
        Nr   )r   )r   r   outputr   r   r   forward(   s   z"VisionEfficientTuningModel.forward)
__name__
__module____qualname____doc__strr   r   r   r    __classcell__r   r   r   r   r      s    *r   )typingr   r   r   modelscope.metainfor   'modelscope.models.base.base_torch_modelr   modelscope.models.builderr   modelscope.utils.constantr   vision_efficient_tuningr	   register_moduler   r   r   r   r   <module>   s   