o
    ߥi_                     @   s^   d dl Z d dlZd dlZd dlmZ G dd dejZG dd dejZ	G dd dejZ
dS )    Nc                       s$   e Zd Z fddZdd Z  ZS )	Inceptionc                    s   t    t||d| _tjdd| _t||d| _tjdd| _tj||ddd| _	tjdd| _
t||d| _tjdd| _tj||ddd| _tjdd| _tjdddd| _t||d| _tjdd| _d S )	N   Tinplace   )padding      )strider   )super__init__nnConv2dconv_1x1ReLUrelu_1x1conv_3x3_reducerelu_3x3_reduceconv_3x3relu_3x3conv_5x5_reducerelu_5x5_reduceconv_5x5relu_5x5	MaxPool2dpool	pool_projrelu_pool_proj)selfin_channelsch1x1ch3x3redch3x3ch5x5redch5x5r   	__class__ g/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/cv/video_summarization/base_model.pyr      s   
zInception.__init__c                 C   s   |  | |}| | |}| | |}| | |}| | 	|}| 
|}| | |}tj||||gddS )Nr   )dim)r   r   r   r   r   r   r   r   r   r   r   r   r   torchcat)r   xbranch_1branch_2branch_3branch_4r'   r'   r(   forward   s   
zInception.forward__name__
__module____qualname__r   r1   __classcell__r'   r'   r%   r(   r   
   s    r   c                       &   e Zd Zd fdd	Zdd Z  ZS )	GoogLeNet  c                    s  t    tjdddddd| _tjdd| _tjdddd| _tj	d	d
dd| _
tjdddd| _tjdd| _tjddddd| _tjdd| _tj	d	d
dd| _tjdddd| _tddddddd| _tddddddd| _tjdddd| _tddddddd| _tddddddd| _tddddddd| _tddddddd| _td ddd!ddd| _tjdddd| _td"ddd!ddd| _td"d#dd#ddd| _td$| _td%|| _ d S )&Nr   @      r	   )kernel_sizer
   r   Tr   )r
   	ceil_moder   g-C6?g      ?)alphabetar   )r<      )r<   r   `                i     0   i      p            i   i  i@  i@  i  )r   r   i   )!r   r   r   r   conv1r   relu1r   pool1LocalResponseNormnorm1conv2_reducerelu2_reduceconv2relu2norm2pool2r   inception_3ainception_3bpool3inception_4ainception_4binception_4cinception_4dinception_4epool4inception_5ainception_5bAdaptiveAvgPool2dpool5Linearloss3_classifier)r   num_classesr%   r'   r(   r   *   s0   
zGoogLeNet.__init__c                 C   s   |  | |}| |}| |}| | |}| | |}| |}| 	|}| 
|}| |}| |}| |}| |}| |}| |}| |}| |}| |}| |}| |d}|S )Nr   )rN   rM   rO   rQ   rS   rR   rU   rT   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rd   flatten)r   r,   r'   r'   r(   r1   D   s(   














zGoogLeNet.forward)r9   r2   r'   r'   r%   r(   r8   (   s    r8   c                       r7   )bvlc_googlenetrJ   c                    s*   t t|   tdd| _|| _d| _dS )zmodel for the BVLC GoogLeNet, trained on ImageNet.
        URL: https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenetr9   )rg   )g      Z@g     @]@g     ^@N)r   ri   r   r8   model
input_size
input_mean)r   rk   r%   r'   r(   r   ]   s   
zbvlc_googlenet.__init__c                 C   s   t || j| jftj}|| j tj}t|g d}t|d}t	
|}t| j jjdks9| }t	 # | |}|jjdksM| }| }|tj| }W d    n1 scw   Y  |dS )N)r	   r   r   r   cpu)cv2resizerk   astypenpfloat32rl   	transposeexpand_dimsr*   
from_numpynextrj   
parametersdevicetypecudano_gradrm   numpylinalgnormreshape)r   framer,   
frame_featr'   r'   r(   r1   g   s&   




zbvlc_googlenet.forward)rJ   r2   r'   r'   r%   r(   ri   [   s    
ri   )ro   r}   rr   r*   torch.nnr   Moduler   
Sequentialr8   ri   r'   r'   r'   r(   <module>   s   3