
    kh<                     n    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e      Zy)    N)Path)CallableOptionalUnion)download_urlverify_str_arg)VisionDatasetc                        e Zd ZdZdZ	 	 	 	 ddeeef   dee   de	de
dee   d	df fd
Zde	d	ej                  fdZd	e	fdZd	e
fdZddZ x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.
        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.
        transform (callable, optional): A function/transform that takes in a torch Tensor
            and returns a transformed version. E.g, ``transforms.RandomCrop``
    zGhttp://www.cs.toronto.edu/~nitish/unsupervised_video/mnist_test_seq.npyNrootsplitsplit_ratiodownload	transformreturnc                    t         |   ||       t        j                  j	                  | j
                  | j                  j                        | _        | j                  j                  d      d   | _        |t        |dd       || _
        t        |t              st        dt!        |             d|cxk  rdk  sn t#        d	| d
      || _        |r| j'                          | j)                         st+        d      t-        j.                  t1        j2                  t        j                  j	                  | j                  | j                                    }| j                  dk(  r|d | j$                   }n| j                  dk(  r|| j$                  d  }|j5                  dd      j7                  d      j9                         | _        y )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torch
from_numpynpload	transpose	unsqueeze
contiguousdata)selfr   r   r   r   r   r2   r   s          ]/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/moving_mnist.pyr   zMovingMNIST.__init__   sz    	3GGLLDNN4K4KL-b15'+<=
+s+J4P[K\J]^__{(b(YZeYffopqq&MMO!!#]^^T5F5F(W XY:: *$**+DZZ6!((*+DNN1a(2215@@B	    idxc                 ^    | j                   |   }| j                  | j                  |      }|S )z
        Args:
            idx (int): Index
        Returns:
            torch.Tensor: Video frames (torch Tensor[T, C, H, W]). The `T` is the number of frames.
        )r2   r   )r3   r6   r2   s      r4   __getitem__zMovingMNIST.__getitem__B   s.     yy~>>%>>$'Dr5   c                 ,    t        | j                        S N)lenr2   r3   s    r4   __len__zMovingMNIST.__len__O   s    499~r5   c                     t         j                  j                  t         j                  j                  | j                  | j
                              S r:   )r   r   existsr   r!   r#   r<   s    r4   r)   zMovingMNIST._check_existsR   s.    ww~~bggll4+<+<dnnMNNr5   c                     | j                         ry t        | j                  | j                  | j                  d       y )N be083ec986bfe91a449d63653c411eb2)urlr   filenamemd5)r)   r   r"   r!   r#   r<   s    r4   r   zMovingMNIST.downloadU   s3    		""^^2		
r5   )N
   FN)r   N)r    
__module____qualname____doc__r"   r   strr   r   r%   boolr   r   r+   Tensorr8   r=   r)   r   __classcell__)r   s   @r4   r   r      s      UD
  $(,"CCI"C }"C 	"C
 "C H%"C 
"CHs u||  Ot O	
r5   r   )os.pathr   pathlibr   typingr   r   r   numpyr-   r+   torchvision.datasets.utilsr   r   torchvision.datasets.visionr	   r    r5   r4   <module>rT      s+      , ,   C 5S
- S
r5   