o
    _{j
  ã                   @   sH   d dl mZ d dlZddlmZ ddlmZ e ¡ G dd„ deƒƒZ	dS )é    Né   )ÚBaseDataset)ÚDATASETSc                       s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚAudioFeatureDataseta˜  Audio feature dataset for video recognition. Reads the features
    extracted off-line. Annotation file can be that of the rawframe dataset,
    or:

    .. code-block:: txt

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

    Args:
        ann_file (str): Path to the annotation file.
        pipeline (list[dict | callable]): A sequence of data transforms.
        suffix (str): The suffix of the audio feature file. Default: '.npy'.
        kwargs (dict): Other keyword args for `BaseDataset`.
    ú.npyc                    s$   || _ tƒ j||fddi|¤Ž d S )NÚmodalityÚAudio)ÚsuffixÚsuperÚ__init__)ÚselfÚann_fileÚpipeliner	   Úkwargs©Ú	__class__© ú=/root/disk_3tb/HAC/mmaction/datasets/audio_feature_dataset.pyr      s   zAudioFeatureDataset.__init__c           
      C   sR  | j  d¡r
|  ¡ S g }t| j dƒ��}|D ]�}| ¡  ¡ }i }d}|| }| jdurB| | j¡s;t 	| j|¡| j }nt 	| j|¡}||d< |d7 }t
|| ƒ|d< |d7 }dd	„ ||d… D ƒ}|sjJ d
|› �ƒ‚| jrƒ| jdustJ ‚t | j¡}	d|	|< |	|d< nt|ƒdks‹J ‚|d |d< | |¡ qW d  ƒ |S 1 s¢w   Y  |S )z.Load annotation file to get video information.z.jsonÚrr   NÚ
audio_pathr   Útotal_framesc                 S   s   g | ]}t |ƒ‘qS r   )Úint)Ú.0Úxr   r   r   Ú
<listcomp>:   s    z8AudioFeatureDataset.load_annotations.<locals>.<listcomp>zmissing label in line: g      ð?Úlabel)r   ÚendswithÚload_json_annotationsÚopenÚstripÚsplitÚdata_prefixr	   ÚospÚjoinr   Úmulti_classÚnum_classesÚtorchÚzerosÚlenÚappend)
r   Úvideo_infosÚfinÚlineÚ
line_splitÚ
video_infoÚidxÚfilenamer   Úonehotr   r   r   Úload_annotations#   sH   
ÿÿ
å
ÿâz$AudioFeatureDataset.load_annotations)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r2   Ú__classcell__r   r   r   r   r   	   s    r   )
Úos.pathÚpathr"   r&   Úbaser   Úregistryr   Úregister_moduler   r   r   r   r   Ú<module>   s    