U
    Ð‹Ñh>  ã                   @   sh   d dl Zd dlmZ d dlmZmZmZ d dlZ	d dl
Z
d dlmZmZ d dlmZ G dd„ deƒZdS )é    N)ÚPath)ÚCallableÚOptionalÚUnion)Údownload_urlÚverify_str_arg)ÚVisionDatasetc                       s‚   e Zd ZdZdZdeeef ee e	e
ee ddœ‡ fdd„Ze	ejd	œd
d„Ze	dœdd„Ze
dœdd„Zddœdd„Z‡  ZS )ÚMovingMNISTaE  `MovingMNIST <http://www.cs.toronto.edu/~nitish/unsupervised_video/>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset where ``MovingMNIST/mnist_test_seq.npy`` exists.
        split (string, optional): The dataset split, supports ``None`` (default), ``"train"`` and ``"test"``.
            If ``split=None``, the full data is returned.
        split_ratio (int, optional): The split ratio of number of frames. If ``split="train"``, the first split
            frames ``data[:, :split_ratio]`` is returned. If ``split="test"``, the last split frames ``data[:, split_ratio:]``
            is returned. If ``split=None``, this parameter is ignored and the all frames data is returned.
        transform (callable, optional): A function/transform that takes in a torch Tensor
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        download (bool, optional): If true, downloads the dataset from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again.
    zGhttp://www.cs.toronto.edu/~nitish/unsupervised_video/mnist_test_seq.npyNé
   F)ÚrootÚsplitÚsplit_ratioÚdownloadÚ	transformÚreturnc                    s&  t ƒ j||d� tj | j| jj¡| _| j	 
d¡d | _|d k	rLt|ddƒ || _
t|tƒsptdt|ƒ› �ƒ‚n&d|  kr„dks–n td	|› d
�ƒ‚|| _|r¨|  ¡  |  ¡ s¸tdƒ‚t t tj | j| j¡¡¡}| j
dkrð|d | j… }n| j
dk�r
|| jd … }| dd¡ d¡ ¡ | _d S )N)r   ú/éÿÿÿÿr   )ÚtrainÚtestz,`split_ratio` should be an integer, but got é   é   z:`split_ratio` should be `1 <= split_ratio <= 19`, but got z	 instead.z<Dataset not found. You can use download=True to download it.r   r   r   é   )ÚsuperÚ__init__ÚosÚpathÚjoinr   Ú	__class__Ú__name__Ú_base_folderÚ_URLr   Ú	_filenamer   Ú
isinstanceÚintÚ	TypeErrorÚtypeÚ
ValueErrorr   r   Ú_check_existsÚRuntimeErrorÚtorchZ
from_numpyÚnpÚloadZ	transposeZ	unsqueezeÚ
contiguousÚdata)Úselfr   r   r   r   r   r-   ©r   © úO/tmp/user/2202/pip-unpacked-wheel-mjxxo1pc/torchvision/datasets/moving_mnist.pyr      s*    

zMovingMNIST.__init__)Úidxr   c                 C   s"   | j | }| jdk	r|  |¡}|S )z«
        Args:
            index (int): Index
        Returns:
            torch.Tensor: Video frames (torch Tensor[T, C, H, W]). The `T` is the number of frames.
        N)r-   r   )r.   r2   r-   r0   r0   r1   Ú__getitem__B   s    


zMovingMNIST.__getitem__)r   c                 C   s
   t | jƒS ©N)Úlenr-   ©r.   r0   r0   r1   Ú__len__O   s    zMovingMNIST.__len__c                 C   s   t j t j | j| j¡¡S r4   )r   r   Úexistsr   r   r!   r6   r0   r0   r1   r'   R   s    zMovingMNIST._check_existsc                 C   s&   |   ¡ rd S t| j| j| jdd� d S )NZ be083ec986bfe91a449d63653c411eb2)Úurlr   ÚfilenameÚmd5)r'   r   r    r   r!   r6   r0   r0   r1   r   U   s    üzMovingMNIST.download)Nr
   FN)r   Ú
__module__Ú__qualname__Ú__doc__r    r   Ústrr   r   r#   Úboolr   r   r)   ZTensorr3   r7   r'   r   Ú__classcell__r0   r0   r/   r1   r	      s$       ú
ù$r	   )Úos.pathr   Úpathlibr   Útypingr   r   r   Znumpyr*   r)   Ztorchvision.datasets.utilsr   r   Ztorchvision.datasets.visionr   r	   r0   r0   r0   r1   Ú<module>   s   