3
Á3W^  ã               @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é   )Úlist_dir)Úmake_dataset)Ú
VideoClips)ÚVisionDatasetc            
       s>   e Zd ZdZd‡ fdd„	Zedd	„ ƒZd
d„ Zdd„ Z‡  Z	S )ÚKinetics400až  
    `Kinetics-400 <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
    dataset.

    Kinetics-400 is an action recognition video dataset.
    This dataset consider every video as a collection of video clips of fixed size, specified
    by ``frames_per_clip``, where the step in frames between each clip is given by
    ``step_between_clips``.

    To give an example, for 2 videos with 10 and 15 frames respectively, if ``frames_per_clip=5``
    and ``step_between_clips=5``, the dataset size will be (2 + 3) = 5, where the first two
    elements will come from video 1, and the next three elements from video 2.
    Note that we drop clips which do not have exactly ``frames_per_clip`` elements, so not all
    frames in a video might be present.

    Internally, it uses a VideoClips object to handle clip creation.

    Args:
        root (string): Root directory of the Kinetics-400 Dataset.
        frames_per_clip (int): number of frames in a clip
        step_between_clips (int): number of frames between each clip
        transform (callable, optional): A function/transform that  takes in a TxHxWxC video
            and returns a transformed version.

    Returns:
        video (Tensor[T, H, W, C]): the `T` video frames
        audio(Tensor[K, L]): the audio frames, where `K` is the number of channels
            and `L` is the number of points
        label (int): class of the video clip
    r   NÚavié    c                sŒ   t t| ƒj|ƒ ttt|ƒƒƒ‰ ‡ fdd„ttˆ ƒƒD ƒ}t| j	||d d�| _
ˆ | _dd„ | j
D ƒ}t|||||||	|
||d�
| _|| _d S )Nc                s   i | ]}|ˆ | “qS © r	   )Ú.0Úi)Úclassesr	   úD/tmp/pip-build-7wfi2gtz/torchvision/torchvision/datasets/kinetics.pyú
<dictcomp>.   s    z(Kinetics400.__init__.<locals>.<dictcomp>)Zis_valid_filec             S   s   g | ]}|d  ‘qS )r   r	   )r
   Úxr	   r	   r   ú
<listcomp>1   s    z(Kinetics400.__init__.<locals>.<listcomp>)Únum_workersÚ_video_widthÚ_video_heightÚ_video_min_dimensionÚ_audio_samples)Úsuperr   Ú__init__ÚlistÚsortedr   ÚrangeÚlenr   ÚrootÚsamplesr   r   Úvideo_clipsÚ	transform)Úselfr   Zframes_per_clipZstep_between_clipsZ
frame_rateÚ
extensionsr   Z_precomputed_metadatar   r   r   r   r   Zclass_to_idxZ
video_list)Ú	__class__)r   r   r   '   s$    
zKinetics400.__init__c             C   s   | j jS )N)r   Úmetadata)r    r	   r	   r   r#   @   s    zKinetics400.metadatac             C   s
   | j jƒ S )N)r   Z	num_clips)r    r	   r	   r   Ú__len__D   s    zKinetics400.__len__c             C   s@   | j j|ƒ\}}}}| j| d }| jd k	r6| j|ƒ}|||fS )Nr   )r   Zget_clipr   r   )r    ÚidxÚvideoÚaudioÚinfoZ	video_idxÚlabelr	   r	   r   Ú__getitem__G   s
    

zKinetics400.__getitem__©r   )
r   Nr+   NNr   r   r   r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr#   r$   r*   Ú__classcell__r	   r	   )r"   r   r      s      r   N)	Úutilsr   Zfolderr   Zvideo_utilsr   Zvisionr   r   r	   r	   r	   r   Ú<module>   s   