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rdksn td	| d
|| _|r|   |  st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    S/var/www/html/venv/lib/python3.8/site-packages/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   numpyr*   r)   Ztorchvision.datasets.utilsr   r   Ztorchvision.datasets.visionr   r	   r0   r0   r0   r1   <module>   s   