o
    _{jý  ã                   @   s@   d dl mZ ddlmZ ddlmZ e ¡ G dd„ deƒƒZdS )é    Né   )ÚRawframeDataset)ÚDATASETSc                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚAudioVisualDatasetaÎ  Dataset that reads both audio and visual data, supporting both rawframes
    and videos. The annotation file is same as that of the rawframe dataset,
    such as:

    .. code-block:: txt

        some/directory-1 163 1
        some/directory-2 122 1
        some/directory-3 258 2
        some/directory-4 234 2
        some/directory-5 295 3
        some/directory-6 121 3

    Args:
        ann_file (str): Path to the annotation file.
        pipeline (list[dict | callable]): A sequence of data transforms.
        audio_prefix (str): Directory of the audio files.
        kwargs (dict): Other keyword args for `RawframeDataset`. `video_prefix`
            is also allowed if pipeline is designed for videos.
    c                    s<   || _ | dd ¡| _| dd ¡| _tƒ j||fi |¤Ž d S )NÚvideo_prefixÚdata_prefix)Úaudio_prefixÚpopr   Úgetr   ÚsuperÚ__init__)ÚselfÚann_fileÚpipeliner   Úkwargs©Ú	__class__© ú</root/disk_3tb/HAC/mmaction/datasets/audio_visual_dataset.pyr      s   zAudioVisualDataset.__init__c                 C   s„  g }t | jdƒ�°}|D ]¤}| ¡  ¡ }i }d}|| }| jd ur-t | j|d ¡}||d< | jr=t | j|d ¡}	|	|d< | jd urMt | j|¡}||d< |d7 }| j	rkt
|| ƒ|d	< t
||d  ƒ|d
< |d7 }nt
|| ƒ|d
< |d7 }dd„ ||d … D ƒ}
t|
ƒs�J d|› �ƒ‚| jrœ| jd us—J ‚|
|d< nt|
ƒdks¤J ‚|
d |d< | |¡ qW d   ƒ |S 1 s»w   Y  |S )NÚrr   z.npyÚ
audio_pathz.mp4ÚfilenameÚ	frame_dirr   ÚoffsetÚtotal_framesé   c                 S   s   g | ]}t |ƒ‘qS r   )Úint)Ú.0Úxr   r   r   Ú
<listcomp>C   s    z7AudioVisualDataset.load_annotations.<locals>.<listcomp>zmissing label in line: Úlabel)Úopenr   ÚstripÚsplitr   ÚospÚjoinr   r   Zwith_offsetr   ÚlenÚmulti_classÚnum_classesÚappend)r   Úvideo_infosÚfinÚlineÚ
line_splitÚ
video_infoÚidxr   r   Ú
video_pathr    r   r   r   Úload_annotations$   sP   
ÿÿ


Ü
ÿ&Ú&z#AudioVisualDataset.load_annotations)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   Ú__classcell__r   r   r   r   r      s    r   )	Úos.pathÚpathr$   Úrawframe_datasetr   Úregistryr   Úregister_moduler   r   r   r   r   Ú<module>   s
    