o
    _{jx	  ã                   @   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 )ÚVideoDataseta  Video dataset for action recognition.

    The dataset loads raw videos and apply specified transforms to return a
    dict containing the frame tensors and other information.

    The ann_file is a text file with multiple lines, and each line indicates
    a sample video with the filepath and label, which are split with a
    whitespace. Example of a annotation file:

    .. code-block:: txt

        some/path/000.mp4 1
        some/path/001.mp4 1
        some/path/002.mp4 2
        some/path/003.mp4 2
        some/path/004.mp4 3
        some/path/005.mp4 3


    Args:
        ann_file (str): Path to the annotation file.
        pipeline (list[dict | callable]): A sequence of data transforms.
        start_index (int): Specify a start index for frames in consideration of
            different filename format. However, when taking videos as input,
            it should be set to 0, since frames loaded from videos count
            from 0. Default: 0.
        **kwargs: Keyword arguments for ``BaseDataset``.
    r   c                    s   t ƒ j||fd|i|¤Ž d S )NÚstart_index)ÚsuperÚ__init__)ÚselfÚann_fileÚpipeliner   Úkwargs©Ú	__class__© ú5/root/disk_3tb/HAC/mmaction/datasets/video_dataset.pyr   (   s   zVideoDataset.__init__c                 C   sò   | j  d¡r
|  ¡ S g }t| j dƒ�]}|D ]Q}| ¡  ¡ }| jrD| jdus'J ‚|d |dd… }}tt	t
|ƒƒ}t | j¡}d||< n|\}}t
|ƒ}| jdurXt | j|¡}| t|| jra|n|d�¡ qW d  ƒ |S 1 srw   Y  |S )z.Load annotation file to get video information.z.jsonÚrNr   r   g      ð?)ÚfilenameÚlabel)r
   ÚendswithÚload_json_annotationsÚopenÚstripÚsplitÚmulti_classÚnum_classesÚlistÚmapÚintÚtorchÚzerosÚdata_prefixÚospÚjoinÚappendÚdict)r	   Úvideo_infosÚfinÚlineÚ
line_splitr   r   Úonehotr   r   r   Úload_annotations+   s6   

þÿó
ÿîzVideoDataset.load_annotations)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   Ú__classcell__r   r   r   r   r   	   s    r   )
Úos.pathÚpathr!   r   Úbaser   Úregistryr   Úregister_moduler   r   r   r   r   Ú<module>   s    