o
    i                     @   sr   d dl Z d dlZd dlmZ d dlm  mZ d dlZd dlm	Z	 d dl
mZmZ d dlmZ G dd de	ZdS )    N)FunASRModel)MossFormerEncoderMossFormer_MaskNet)MossFormerDecoderc                       s<   e Zd ZdZ									d fd	d
	Zdd Z  ZS )
MossFormera  The MossFormer model for separating input mixed speech into different speaker's speech.

    Arguments
    ---------
    in_channels : int
        Number of channels at the output of the encoder.
    out_channels : int
        Number of channels that would be inputted to the intra and inter blocks.
    num_blocks : int
        Number of layers of Dual Computation Block.
    norm : str
        Normalization type.
    num_spks : int
        Number of sources (speakers).
    skip_around_intra : bool
        Skip connection around intra.
    use_global_pos_enc : bool
        Global positional encodings.
    max_length : int
        Maximum sequence length.
    kernel_size: int
        Encoder and decoder kernel size
             ln   T N  c
           
   
      sZ   t t|   || _t||dd| _t||||||||	d| _t|d||d dd| _	d S )N   )kernel_sizeout_channelsin_channels)r   r   
num_blocksnormnum_spksskip_around_intrause_global_pos_enc
max_lengthr   F)r   r   r   stridebias)
superr   __init__r   r   encr   mask_netr   dec)
selfr   r   r   r   r   r   r   r   r   	__class__ S/home/ubuntu/.local/lib/python3.10/site-packages/funasr/models/mossformer/e2e_ss.pyr   $   s,   
zMossFormer.__init__c           	         s     |} |}t|g j }|| tj fddt jD dd}|d}|d}||krDt	|ddd|| f}n|d d d |d d f }g }t jD ]}|
|d d d d |f  qX|S )Nc                    s    g | ]}  | d qS ))r   	unsqueeze).0ir   sep_xr!   r"   
<listcomp>R   s     z&MossFormer.forward.<locals>.<listcomp>r#   )dimr   r   )r   r   torchstackr   catrangesizeFpadappend)	r   inputxmask
est_sourceT_originT_estoutspkr!   r'   r"   forwardJ   s"   



zMossFormer.forward)	r   r   r   r	   r
   r   TTr   )__name__
__module____qualname____doc__r   r;   __classcell__r!   r!   r   r"   r      s    &r   )mathr+   torch.nnnntorch.nn.functional
functionalr0   copyfunasr.models.base_modelr   (funasr.models.encoder.mossformer_encoderr   r   (funasr.models.decoder.mossformer_decoderr   r   r!   r!   r!   r"   <module>   s    