o
    ߥi	                     @   sv  d dl Z d dlZd dlZd dlZd dlZd dlm  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 d dlmZmZ d d	lmZ d
dlmZ e Zi d dd
dddddddddddddddddddd d!d"d#d$d%d&d'd(d)Zd*d*gZeeee  ej!g d+g d+d,gZ"ej#ej$ej$d-G d.d/ d/eZ%d0d1 Z&dS )2    N)Image)nn)
transforms)Models)
TorchModel)MODELS)	ModelFileTasks)
get_logger   )StaticGestureNetunrecogone   two   bixin   yaogun   zan   fist   ok   tuoju	   d_bixin
   d_fist_left   d_fist_right   d_hand   fashe   five   nohandp   )      ?r,   r,   )meanstd)module_namec                       s&   e Zd Zd fdd	Zdd Z  ZS )
HandStaticr   c                    s   t  j|||d| t | _tj rd| _nd| _tjd	|t
j| jd| _| j| j | j| j | j  || _| jdkr_| jdkr_| jd	| j td	| j d S d	| _td
 d S )N)	model_dir	device_idcudacpuz{}/{})map_locationr   zcuda:{}zUse GPU: {}zUse CPU for inference)super__init__r   modeltorchr3   is_availabledeviceloadformatr   TORCH_MODEL_BIN_FILEparamsload_state_dicttoevalr2   loggerinfo)selfr1   r2   argskwargs	__class__ _/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/cv/hand_static/hand_model.pyr8   5   s,   

zHandStatic.__init__c                 C   s   |  |}|S )N)r9   )rF   xpred_resultrK   rK   rL   forwardN   s   
zHandStatic.forward)r   )__name__
__module____qualname__r8   rO   __classcell__rK   rK   rI   rL   r0   2   s    r0   c                 C   sj   |    } t| } t| }|d| }||}t|	dd }t
|}td| |S )Nr   r   zpred result: {})r4   numpyr   	fromarrayspatial_transform	unsqueezerB   floatintmaxmap_idxgetrD   rE   r>   )imgr9   r<   clipoutputs	predictedrN   rK   rK   rL   inferS   s   

ra   )'ossyscv2rT   npr:   torch.nn.functionalr   
functionalFPILr   torchvisionr   modelscope.metainfor   modelscope.models.baser   modelscope.models.builderr   modelscope.utils.constantr   r	   modelscope.utils.loggerr
   networksr   rD   r[   img_sizeComposeResizeToTensor	NormalizerV   register_modulehand_staticr0   ra   rK   rK   rK   rL   <module>   st   	
 