ó
    EñiÔR  ã                   ó\  • S SK r S SKrS SKJrJr  S SKJr  S SKJr  S SKJ	r	J
r
JrJr  S SKrS SKrS SKJr  SSKJrJr  S	S
KJr  S	SKJrJr  S	SKJr  \\R"                  \R"                  \\R:                     \\R:                     4   r\\R"                  \R"                  \\R:                     4   rSr  " S S\\5      r! " S S\!5      r" " S S\!5      r# " S S\!5      r$ " S S\!5      r% " S S\!5      r&S\'S\R:                  4S jr(S\'S\\R:                  \R:                  4   4S jr)g)é    N)ÚABCÚabstractmethod)Úglob©ÚPath)ÚAnyÚCallableÚOptionalÚUnion)ÚImageé   )Ú
decode_pngÚ	read_fileé   )Údefault_loader)Ú	_read_pfmÚverify_str_arg)ÚVisionDataset)Ú	KittiFlowÚSintelÚFlyingThings3DÚFlyingChairsÚHD1Kc            	       ó8  ^ • \ rS rSrSrS\4S\\\4   S\	\
   S\
\/\4   SS4U 4S jjjrS	\S\\R                  \R                  4   4S
 jr\S	\4S j5       rS\S\\\4   4S jrS\4S jrS\S\R0                  R2                  R4                  4S jrSrU =r$ )ÚFlowDataseté   FNÚrootÚ
transformsÚloaderÚreturnc                 óT   >• [         TU ]  US9  X l        / U l        / U l        X0l        g )N)r   )ÚsuperÚ__init__r   Ú
_flow_listÚ_image_listÚ_loader)Úselfr   r   r   Ú	__class__s       €Ú_/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/_optical_flow.pyr#   ÚFlowDataset.__init__$   s.   ø€ ô 	‰Ñ˜dÐÑ#Ø$Œà%'ˆŒØ,.ˆÔØ�ó    Ú	file_namec                 ó$   • U R                  U5      $ ©N)r&   ©r'   r,   s     r)   Ú	_read_imgÚFlowDataset._read_img2   s   € Ø�|‰|˜IÓ&Ð&r+   c                 ó   • g r.   © r/   s     r)   Ú
_read_flowÚFlowDataset._read_flow5   s   € ð 	r+   Úindexc                 ó˜  • U R                  U R                  U   S   5      nU R                  U R                  U   S   5      nU R                  (       a7  U R                  U R                  U   5      nU R                  (       a  Uu  pEOS nOS =pEU R
                  b  U R                  X#XE5      u  p#pEU R                  (       d  Ub  X#XE4$ X#U4$ )Nr   r   )r0   r%   r$   r4   Ú_has_builtin_flow_maskr   )r'   r6   Úimg1Úimg2ÚflowÚvalid_flow_masks         r)   Ú__getitem__ÚFlowDataset.__getitem__:   s¿   € à�~‰~˜d×.Ñ.¨uÑ5°aÑ8Ó9ˆØ�~‰~˜d×.Ñ.¨uÑ5°aÑ8Ó9ˆà�?�?Ø—?‘? 4§?¡?°5Ñ#9Ó:ˆDØ×*×*Ø(,Ñ%��oà"&‘à%)Ð)ˆDà�?‰?Ñ&Ø04·±ÀÈDÓ0bÑ-ˆD˜à×&×&¨/Ñ*Eà˜tÐ4Ð4à˜tÐ#Ð#r+   c                 ó,   • [        U R                  5      $ r.   )Úlenr%   )r'   s    r)   Ú__len__ÚFlowDataset.__len__Q   s   € Ü�4×#Ñ#Ó$Ð$r+   Úvc                 ó\   • [         R                  R                  R                  U /U-  5      $ r.   )ÚtorchÚutilsÚdataÚConcatDataset)r'   rC   s     r)   Ú__rmul__ÚFlowDataset.__rmul__T   s#   € Ü�{‰{×Ñ×-Ñ-¨t¨f°q©jÓ9Ð9r+   )r$   r%   r&   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r8   r   r   Ústrr   r
   r	   r   r#   r   rE   ÚTensorr0   r   r4   ÚintÚT1ÚT2r=   rA   rF   rG   rH   rI   Ú__static_attributes__Ú__classcell__©r(   s   @r)   r   r      së   ø† ð #Ðð
 *.Ø'5ñ	à�C˜�IÑðð ˜XÑ&ðð ˜#˜ ˜Ñ$ð	ð
 
÷ð ð' 3ð '¨5°·±¸e¿l¹lÐ1JÑ+Kô 'ð ð Có ó ðð$ ð $¨¨r°2¨v©ô $ð.%˜ô %ð:˜#ð : %§+¡+×"2Ñ"2×"@Ñ"@÷ :ò :r+   r   c                   ó¸   ^ • \ rS rSrSrSSS\4S\\\4   S\S\S	\	\
   S
\
\/\4   SS4U 4S jjjrS\S\\\4   4U 4S jjrS\S\R$                  4S jrSrU =r$ )r   éX   a:  `Sintel <http://sintel.is.tue.mpg.de/>`_ Dataset for optical flow.

The dataset is expected to have the following structure: ::

    root
        Sintel
            testing
                clean
                    scene_1
                    scene_2
                    ...
                final
                    scene_1
                    scene_2
                    ...
            training
                clean
                    scene_1
                    scene_2
                    ...
                final
                    scene_1
                    scene_2
                    ...
                flow
                    scene_1
                    scene_2
                    ...

Args:
    root (str or ``pathlib.Path``): Root directory of the Sintel Dataset.
    split (string, optional): The dataset split, either "train" (default) or "test"
    pass_name (string, optional): The pass to use, either "clean" (default), "final", or "both". See link above for
        details on the different passes.
    transforms (callable, optional): A function/transform that takes in
        ``img1, img2, flow, valid_flow_mask`` and returns a transformed version.
        ``valid_flow_mask`` is expected for consistency with other datasets which
        return a built-in valid mask, such as :class:`~torchvision.datasets.KittiFlow`.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.
ÚtrainÚcleanNr   ÚsplitÚ	pass_namer   r   r    c                 ó:  >• [         TU ]  XUS9  [        USSS9  [        USSS9  US:X  a  SS	/OU/n[        U5      S
-  nUS-  S-  nU HÍ  nUS:X  a  SOUnX-  U-  n	[        R
                  " U	5       HŸ  n
[        [        [        Xš-  S-  5      5      5      n[        [        U5      S-
  5       H"  nU =R                  X¼   X¼S-      //-  sl        M$     US:X  d  Mj  U =R                  [        [        [        Xz-  S-  5      5      5      -  sl        M¡     MÏ     g )N©r   r   r   r[   ©rY   Útest©Úvalid_valuesr\   ©rZ   ÚfinalÚbothre   rZ   rd   r   Útrainingr;   rY   ú*.pngr   ú*.flo)r"   r#   r   r   ÚosÚlistdirÚsortedr   rO   Úranger@   r%   r$   )r'   r   r[   r\   r   r   ÚpassesÚ	flow_rootÚ	split_dirÚ
image_rootÚsceneÚ
image_listÚir(   s                €r)   r#   ÚSintel.__init__„   s   ø€ ô 	‰Ñ˜dÀ&ÐÑIä�u˜gÐ4EÒFÜ�y +Ð<VÒWØ'0°FÓ':�'˜7Ñ#ÀÀˆä�D‹z˜HÑ$ˆØ˜:Ñ%¨Ñ.ˆ	ãˆIØ&+¨wÓ&6™
¸EˆIØÑ)¨IÑ5ˆJÜŸš JÖ/�Ü#¤D¬¨ZÑ-?À'Ñ-IÓ)JÓ$KÓL�
Üœs :›°Ñ2Ö3�AØ×$Ò$¨*©-¸ÈÁEÑ9JÐ)KÐ(LÑL×$ñ 4ð ˜GÕ#Ø—O’O¤v¬d´3°yÑ7HÈ7Ñ7RÓ3SÓ.TÓ'UÑU—Oó 0ò  r+   r6   c                 ó"   >• [         TU ]  U5      $ ©a¤  Return example at given index.

Args:
    index(int): The index of the example to retrieve

Returns:
    tuple: A 3-tuple with ``(img1, img2, flow)``.
    The flow is a numpy array of shape (2, H, W) and the images are PIL images.
    ``flow`` is None if ``split="test"``.
    If a valid flow mask is generated within the ``transforms`` parameter,
    a 4-tuple with ``(img1, img2, flow, valid_flow_mask)`` is returned.
©r"   r=   ©r'   r6   r(   s     €r)   r=   ÚSintel.__getitem__    ó   ø€ ô ‰wÑ" 5Ó)Ð)r+   r,   c                 ó   • [        U5      $ r.   ©Ú	_read_flor/   s     r)   r4   ÚSintel._read_flow¯   ó   € Ü˜Ó#Ð#r+   r3   ©rK   rL   rM   rN   Ú__doc__r   r   rO   r   r
   r	   r   r#   rQ   rR   rS   r=   ÚnpÚndarrayr4   rT   rU   rV   s   @r)   r   r   X   s³   ø† ñ)ð\ Ø Ø)-Ø'5ñVà�C˜�IÑðVð ðVð ð	Vð
 ˜XÑ&ðVð ˜#˜ ˜Ñ$ðVð 
÷Vð Vð8* ð *¨¨r°2¨v©÷ *ð$ Cð $¨B¯J©J÷ $ò $r+   r   c                   óÔ   ^ • \ rS rSrSrSrSS\4S\\\	4   S\S\
\   S	\\/\4   S
S4
U 4S jjjrS\S
\\\4   4U 4S jjrS\S
\\R(                  \R(                  4   4S jrSrU =r$ )r   é³   aw  `KITTI <http://www.cvlibs.net/datasets/kitti/eval_scene_flow.php?benchmark=flow>`__ dataset for optical flow (2015).

The dataset is expected to have the following structure: ::

    root
        KittiFlow
            testing
                image_2
            training
                image_2
                flow_occ

Args:
    root (str or ``pathlib.Path``): Root directory of the KittiFlow Dataset.
    split (string, optional): The dataset split, either "train" (default) or "test"
    transforms (callable, optional): A function/transform that takes in
        ``img1, img2, flow, valid_flow_mask`` and returns a transformed version.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.
TrY   Nr   r[   r   r   r    c                 óÒ  >• [         T	U ]  XUS9  [        USSS9  [        U5      S-  US-   -  n[	        [        [        US-  S-  5      5      5      n[	        [        [        US-  S	-  5      5      5      nU(       a  U(       d  [        S
5      e[        XV5       H  u  pxU =R                  Xx//-  sl	        M     US:X  a)  [	        [        [        US-  S-  5      5      5      U l
        g g )Nr^   r[   r_   ra   r   ÚingÚimage_2z*_10.pngz*_11.pngzZCould not find the Kitti flow images. Please make sure the directory structure is correct.rY   Úflow_occ)r"   r#   r   r   rk   r   rO   ÚFileNotFoundErrorÚzipr%   r$   )
r'   r   r[   r   r   Úimages1Úimages2r9   r:   r(   s
            €r)   r#   ÚKittiFlow.__init__Ì   sã   ø€ ô 	‰Ñ˜dÀ&ÐÑIä�u˜gÐ4EÒFä�D‹z˜KÑ'¨5°5©=Ñ9ˆÜœœc $¨Ñ"2°ZÑ"?Ó@ÓAÓBˆÜœœc $¨Ñ"2°ZÑ"?Ó@ÓAÓBˆæžgÜ#Ølóð ô ˜gÖ/‰JˆDØ×Ò $  Ñ.×ñ 0ð �GÓÜ$¤T¬#¨d°ZÑ.?À*Ñ.LÓ*MÓ%NÓOˆD�Oð r+   r6   c                 ó"   >• [         TU ]  U5      $ )a¬  Return example at given index.

Args:
    index(int): The index of the example to retrieve

Returns:
    tuple: A 4-tuple with ``(img1, img2, flow, valid_flow_mask)``
    where ``valid_flow_mask`` is a numpy boolean mask of shape (H, W)
    indicating which flow values are valid. The flow is a numpy array of
    shape (2, H, W) and the images are PIL images. ``flow`` and ``valid_flow_mask`` are None if
    ``split="test"``.
rw   rx   s     €r)   r=   ÚKittiFlow.__getitem__æ   rz   r+   r,   c                 ó   • [        U5      $ r.   ©Ú)_read_16bits_png_with_flow_and_valid_maskr/   s     r)   r4   ÚKittiFlow._read_flowõ   ó   € Ü8¸ÓCÐCr+   )r$   )rK   rL   rM   rN   r�   r8   r   r   rO   r   r
   r	   r   r#   rQ   rR   rS   r=   Útupler‚   rƒ   r4   rT   rU   rV   s   @r)   r   r   ³   s¾   ø† ñð, "Ðð
 Ø)-Ø'5ñPà�C˜�IÑðPð ðPð ˜XÑ&ð	Pð
 ˜#˜ ˜Ñ$ðPð 
÷Pð Pð4* ð *¨¨r°2¨v©÷ *ðD Cð D¨E°"·*±*¸b¿j¹jÐ2HÑ,I÷ Dò Dr+   r   c            	       óœ   ^ • \ rS rSrSrSS\\\4   S\S\\	   SS4U 4S jjjr
S	\S\\\4   4U 4S
 jjrS\S\R                   4S jrSrU =r$ )r   éù   aÖ  `FlyingChairs <https://lmb.informatik.uni-freiburg.de/resources/datasets/FlyingChairs.en.html#flyingchairs>`_ Dataset for optical flow.

You will also need to download the FlyingChairs_train_val.txt file from the dataset page.

The dataset is expected to have the following structure: ::

    root
        FlyingChairs
            data
                00001_flow.flo
                00001_img1.ppm
                00001_img2.ppm
                ...
            FlyingChairs_train_val.txt


Args:
    root (str or ``pathlib.Path``): Root directory of the FlyingChairs Dataset.
    split (string, optional): The dataset split, either "train" (default) or "val"
    transforms (callable, optional): A function/transform that takes in
        ``img1, img2, flow, valid_flow_mask`` and returns a transformed version.
        ``valid_flow_mask`` is expected for consistency with other datasets which
        return a built-in valid mask, such as :class:`~torchvision.datasets.KittiFlow`.
Nr   r[   r   r    c                 ó”  >• [         T
U ]  XS9  [        USSS9  [        U5      S-  n[	        [        [        US-  S-  5      5      5      n[	        [        [        US-  S-  5      5      5      nS	n[        R                  R                  X-  5      (       d  [        S
5      e[        R                  " [        X-  5      [        R                  S9n[        [        U5      5       Hb  nXx   n	US:X  a  U	S:X  d  US:X  d  M  U	S:X  d  M#  U =R                   XX   /-  sl        U =R"                  USU-     USU-  S-      //-  sl        Md     g )N)r   r   r[   )rY   Úvalra   r   rG   z*.ppmrh   zFlyingChairs_train_val.txtzmThe FlyingChairs_train_val.txt file was not found - please download it from the dataset page (see docstring).)ÚdtyperY   r   rš   r   )r"   r#   r   r   rk   r   rO   ri   ÚpathÚexistsrŠ   r‚   ÚloadtxtÚint32rl   r@   r$   r%   )r'   r   r[   r   ÚimagesÚflowsÚsplit_file_nameÚ
split_listrs   Úsplit_idr(   s             €r)   r#   ÚFlyingChairs.__init__  s&  ø€ Ü‰Ñ˜dÐÑ:ä�u˜gÐ4DÒEä�D‹z˜NÑ*ˆÜœœS ¨¡°Ñ!8Ó9Ó:Ó;ˆÜ”tœC  v¡°Ñ 7Ó8Ó9Ó:ˆà6ˆä�w‰w�~‰~˜dÑ4×5Ñ5Ü#Øóð ô —Z’Z¤ DÑ$:Ó ;Ä2Ç8Á8ÑLˆ
Ü”s˜5“zÖ"ˆAØ!‘}ˆHØ˜Ó  X°£]¸À½È8ÐWXÍ=Ø—’ E¡H :Ñ-•Ø× Ò  f¨Q°©U¡m°V¸AÀ¹EÀA¹IÑ5FÐ%GÐ$HÑH× ò	 #r+   r6   c                 ó"   >• [         TU ]  U5      $ )a£  Return example at given index.

Args:
    index(int): The index of the example to retrieve

Returns:
    tuple: A 3-tuple with ``(img1, img2, flow)``.
    The flow is a numpy array of shape (2, H, W) and the images are PIL images.
    ``flow`` is None if ``split="val"``.
    If a valid flow mask is generated within the ``transforms`` parameter,
    a 4-tuple with ``(img1, img2, flow, valid_flow_mask)`` is returned.
rw   rx   s     €r)   r=   ÚFlyingChairs.__getitem__*  rz   r+   r,   c                 ó   • [        U5      $ r.   r|   r/   s     r)   r4   ÚFlyingChairs._read_flow9  r   r+   r3   )rY   N)rK   rL   rM   rN   r�   r   rO   r   r
   r	   r#   rQ   rR   rS   r=   r‚   rƒ   r4   rT   rU   rV   s   @r)   r   r   ù   s|   ø† ññ2I˜U 3¨ 9Ñ-ð I°cð IÐQYÐZbÑQcð IÐos÷ Ið Ið.* ð *¨¨r°2¨v©÷ *ð$ Cð $¨B¯J©J÷ $ò $r+   r   c                   ó¾   ^ • \ rS rSrSrSSSS\4S\\\4   S\S	\S
\S\	\
   S\
\/\4   SS4U 4S jjjrS\S\\\4   4U 4S jjrS\S\R$                  4S jrSrU =r$ )r   i=  a¶  `FlyingThings3D <https://lmb.informatik.uni-freiburg.de/resources/datasets/SceneFlowDatasets.en.html>`_ dataset for optical flow.

The dataset is expected to have the following structure: ::

    root
        FlyingThings3D
            frames_cleanpass
                TEST
                TRAIN
            frames_finalpass
                TEST
                TRAIN
            optical_flow
                TEST
                TRAIN

Args:
    root (str or ``pathlib.Path``): Root directory of the intel FlyingThings3D Dataset.
    split (string, optional): The dataset split, either "train" (default) or "test"
    pass_name (string, optional): The pass to use, either "clean" (default) or "final" or "both". See link above for
        details on the different passes.
    camera (string, optional): Which camera to return images from. Can be either "left" (default) or "right" or "both".
    transforms (callable, optional): A function/transform that takes in
        ``img1, img2, flow, valid_flow_mask`` and returns a transformed version.
        ``valid_flow_mask`` is expected for consistency with other datasets which
        return a built-in valid mask, such as :class:`~torchvision.datasets.KittiFlow`.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.
rY   rZ   ÚleftNr   r[   r\   Úcamerar   r   r    c           
      ó4  >^^• [         TU ]  XUS9  [        USSS9  UR                  5       n[        USSS9  S/S/SS/S.U   n[        TS	S
S9  TS:X  a  SS/OT/n[	        U5      S-  nSn	[
        R                  " XxU	5       GH�  u  nmm[        [        [        X-  U-  S-  5      5      5      n
[        U4S jU
 5       5      n
[        [        [        US-  U-  S-  5      5      5      n[        UU4S jU 5       5      nU
(       a  U(       d  [        S5      e[        X«5       Hê  u  pÍ[        [        [        US-  5      5      5      n[        [        [        US-  5      5      5      n[        [        U5      S-
  5       HŠ  nTS:X  a<  U =R                  UU   UUS-      //-  sl        U =R                  UU   /-  sl        ME  TS:X  d  MM  U =R                  UUS-      UU   //-  sl        U =R                  UUS-      /-  sl        MŒ     Mì     GM“     g )Nr^   r[   r_   ra   r\   rc   Úframes_cleanpassÚframes_finalpassr¬   )r«   Úrightre   re   r«   r°   r   )Úinto_futureÚ	into_pastz*/*c              3   ó@   >#   • U  H  n[        U5      T-  v •  M     g 7fr.   r   )Ú.0Ú	image_dirr¬   s     €r)   Ú	<genexpr>Ú*FlyingThings3D.__init__.<locals>.<genexpr>z  s   øé € ÐUÊ*¸Y¤ Y£°&Ö 8Ê*ùs   ƒÚoptical_flowc              3   óF   >#   • U  H  n[        U5      T-  T-  v •  M     g 7fr.   r   )r´   Úflow_dirr¬   Ú	directions     €€r)   r¶   r·   }  s!   øé € Ð]ÒS\Àxœt H›~°	Ñ9¸FÖBÒS\ùs   ƒ!zcCould not find the FlyingThings3D flow images. Please make sure the directory structure is correct.rg   z*.pfmr   r±   r²   )r"   r#   r   Úupperr   Ú	itertoolsÚproductrk   r   rO   rŠ   r‹   rl   r@   r%   r$   )r'   r   r[   r\   r¬   r   r   rm   ÚcamerasÚ
directionsÚ
image_dirsÚ	flow_dirsrµ   rº   r    r¡   rs   r»   r(   s       `            @€r)   r#   ÚFlyingThings3D.__init__]  s  ú€ ô 	‰Ñ˜dÀ&ÐÑIä�u˜gÐ4EÒFØ—‘“ˆä�y +Ð<VÒWà(Ð)Ø(Ð)Ø'Ð);Ð<ñ
ð ñ	ˆô 	�v˜xÐ6OÒPØ'-°Ó'7�6˜7Ñ#¸f¸Xˆä�D‹zÐ,Ñ,ˆà1ˆ
Ü,5×,=Ò,=¸fÈz×,ZÑ(ˆI�v˜yÜ¤¤S¨Ñ)9¸EÑ)AÀEÑ)IÓ%JÓ KÓLˆJÜÔUÉ*ÓUÓUˆJäœt¤C¨¨~Ñ(=ÀÑ(EÈÑ(MÓ$NÓOÓPˆIÜÕ]ÑS\Ó]Ó]ˆIæ¦YÜ'ðKóð ô
 (+¨:Ö'AÑ#�	Ü¤¤S¨°WÑ)<Ó%=Ó >Ó?�Üœt¤C¨°7Ñ(:Ó$;Ó<Ó=�Üœs 5›z¨A™~Ö.�AØ  MÓ1Ø×(Ò(¨f°Q©i¸ÀÀAÁ¹Ð-GÐ,HÑHÕ(ØŸš¨E°!©H¨:Ñ5ŸØ" kÕ1Ø×(Ò(¨f°Q¸±U©m¸VÀA¹YÐ-GÐ,HÑHÕ(ØŸš¨E°!°a±%©L¨>Ñ9Ÿó /ô (Bò -[r+   r6   c                 ó"   >• [         TU ]  U5      $ rv   rw   rx   s     €r)   r=   ÚFlyingThings3D.__getitem__�  rz   r+   r,   c                 ó   • [        U5      $ r.   )r   r/   s     r)   r4   ÚFlyingThings3D._read_flowŸ  r   r+   r3   r€   rV   s   @r)   r   r   =  s¹   ø† ñðD Ø ØØ)-Ø'5ñ1:à�C˜�IÑð1:ð ð1:ð ð	1:ð
 ð1:ð ˜XÑ&ð1:ð ˜#˜ ˜Ñ$ð1:ð 
÷1:ð 1:ðf* ð *¨¨r°2¨v©÷ *ð$ Cð $¨B¯J©J÷ $ò $r+   r   c                   óÔ   ^ • \ rS rSrSrSrSS\4S\\\	4   S\S\
\   S	\\/\4   S
S4
U 4S jjjrS\S
\\R                   \R                   4   4S jrS\S
\\\4   4U 4S jjrSrU =r$ )r   i£  ak  `HD1K <http://hci-benchmark.iwr.uni-heidelberg.de/>`__ dataset for optical flow.

The dataset is expected to have the following structure: ::

    root
        hd1k
            hd1k_challenge
                image_2
            hd1k_flow_gt
                flow_occ
            hd1k_input
                image_2

Args:
    root (str or ``pathlib.Path``): Root directory of the HD1K Dataset.
    split (string, optional): The dataset split, either "train" (default) or "test"
    transforms (callable, optional): A function/transform that takes in
        ``img1, img2, flow, valid_flow_mask`` and returns a transformed version.
    loader (callable, optional): A function to load an image given its path.
        By default, it uses PIL as its image loader, but users could also pass in
        ``torchvision.io.decode_image`` for decoding image data into tensors directly.
TrY   Nr   r[   r   r   r    c           
      óþ  >• [         TU ]  XUS9  [        USSS9  [        U5      S-  nUS:X  a¼  [	        S5       H¬  n[        [        [        US-  S	-  US
 S3-  5      5      5      n[        [        [        US-  S-  US
 S3-  5      5      5      n[	        [        U5      S-
  5       H:  nU =R                  Xh   /-  sl	        U =R                  Xx   XxS-      //-  sl
        M<     M®     Ow[        [        [        US-  S-  S-  5      5      5      n	[        [        [        US-  S-  S-  5      5      5      n
[        Xš5       H  u  p¼U =R                  X¼//-  sl
        M     U R                  (       d  [        S5      eg )Nr^   r[   r_   ra   Úhd1krY   é$   Úhd1k_flow_gtr‰   Ú06dz_*.pngÚ
hd1k_inputrˆ   r   Úhd1k_challengez*10.pngz*11.pngzTCould not find the HD1K images. Please make sure the directory structure is correct.)r"   r#   r   r   rl   rk   r   rO   r@   r$   r%   r‹   rŠ   )r'   r   r[   r   r   Úseq_idxr¡   r    rs   rŒ   r�   Úimage1Úimage2r(   s                €r)   r#   ÚHD1K.__init__½  s�  ø€ ô 	‰Ñ˜dÀ&ÐÑIä�u˜gÐ4EÒFä�D‹z˜FÑ"ˆØ�GÓä  ž9�Üœt¤C¨¨~Ñ(=À
Ñ(JÐPWÐX[È}Ð\bÐMcÑ(cÓ$dÓeÓf�Ü¤¤S¨°Ñ)<¸yÑ)HÈgÐVYÈ]ÐZ`ÐKaÑ)aÓ%bÓ cÓd�Üœs 5›z¨A™~Ö.�AØ—O’O¨© zÑ1•OØ×$Ò$¨&©)°VÀ¹E±]Ð)CÐ(DÑD×$ó /ò %ô œT¤# dÐ-=Ñ&=À	Ñ&IÈIÑ&UÓ"VÓWÓXˆGÜœT¤# dÐ-=Ñ&=À	Ñ&IÈIÑ&UÓ"VÓWÓXˆGÜ"% gÖ"7‘�Ø× Ò  fÐ%5Ð$6Ñ6× ñ #8ð ××Ü#Øfóð ð  r+   r,   c                 ó   • [        U5      $ r.   r’   r/   s     r)   r4   ÚHD1K._read_flowÜ  r•   r+   r6   c                 ó"   >• [         TU ]  U5      $ )a¬  Return example at given index.

Args:
    index(int): The index of the example to retrieve

Returns:
    tuple: A 4-tuple with ``(img1, img2, flow, valid_flow_mask)`` where ``valid_flow_mask``
    is a numpy boolean mask of shape (H, W)
    indicating which flow values are valid. The flow is a numpy array of
    shape (2, H, W) and the images are PIL images. ``flow`` and ``valid_flow_mask`` are None if
    ``split="test"``.
rw   rx   s     €r)   r=   ÚHD1K.__getitem__ß  rz   r+   r3   )rK   rL   rM   rN   r�   r8   r   r   rO   r   r
   r	   r   r#   r–   r‚   rƒ   r4   rQ   rR   rS   r=   rT   rU   rV   s   @r)   r   r   £  s¶   ø† ñð. "Ðð
 Ø)-Ø'5ñà�C˜�IÑðð ðð ˜XÑ&ð	ð
 ˜#˜ ˜Ñ$ðð 
÷ð ð>D Cð D¨E°"·*±*¸b¿j¹jÐ2HÑ,Iô Dð* ð *¨¨r°2¨v©÷ *õ *r+   r   r,   r    c                 óÈ  • [        U S5       n[        R                  " USSS9R                  5       nUS:w  a  [	        S5      e[        R                  " USSS9R                  5       n[        R                  " USSS9R                  5       n[        R                  " US	S
U-  U-  S9nUR                  XCS
5      R                  S
SS5      sSSS5        $ ! , (       d  f       g= f)z#Read .flo file in Middlebury formatÚrbÚcé   )Úcounts   PIEHz)Magic number incorrect. Invalid .flo filez<i4r   z<f4r   r   N)Úopenr‚   ÚfromfileÚtobytesÚ
ValueErrorÚitemÚreshapeÚ	transpose)r,   ÚfÚmagicÚwÚhrG   s         r)   r}   r}   ï  s¸   € ô 
ˆi˜Ô	 !Ü—’˜A˜s¨!Ñ,×4Ñ4Ó6ˆØ�GÓÜÐHÓIÐIä�KŠK˜˜5¨Ñ*×/Ñ/Ó1ˆÜ�KŠK˜˜5¨Ñ*×/Ñ/Ó1ˆÜ�{Š{˜1˜e¨1¨q©5°1©9Ñ5ˆØ�|‰|˜A !Ó$×.Ñ.¨q°!°QÓ7÷ 
×	×	ús   �B<CÃ
C!c                 ó  • [        [        U 5      5      R                  [        R                  5      nUS S2S S 2S S 24   USS S 2S S 24   p2US-
  S-  nUR                  5       nUR                  5       UR                  5       4$ )Nr   i €  é@   )r   r   ÚtorE   Úfloat32ÚboolÚnumpy)r,   Úflow_and_validr;   r<   s       r)   r“   r“      sy   € ä¤	¨)Ó 4Ó5×8Ñ8¼¿¹ÓG€NØ*¨2¨A¨2ªq²!¨8Ñ4°nÀQÊÊ1ÀWÑ6Mˆ/Ø�5‰L˜BÑ€DØ%×*Ñ*Ó,€Oð �:‰:‹<˜×.Ñ.Ó0Ð0Ð0r+   )*r½   ri   Úabcr   r   r   Úpathlibr   Útypingr   r	   r
   r   rí   r‚   rE   ÚPILr   Úio.imager   r   Úfolderr   rF   r   r   Úvisionr   r–   rƒ   rR   rS   Ú__all__r   r   r   r   r   r   rO   r}   r“   r3   r+   r)   Ú<module>r÷      s   ðÛ Û 	ß #Ý Ý ß 1Ó 1ã Û Ý ç ,Ý "ß ,Ý !à
ˆ5�;‰;˜Ÿ™ X¨b¯j©jÑ%9¸8ÀBÇJÁJÑ;OÐOÑP€Ø
ˆ5�;‰;˜Ÿ™ X¨b¯j©jÑ%9Ð9Ñ:€ð€ô7:�#�}ô 7:ôtX$ˆ[ô X$ôvCD�ô CDôLA$�;ô A$ôHc$�[ô c$ôLI*ˆ;ô I*ðX8˜ð 8 §¡ô 8ð"1¸ð 1ÀÀrÇzÁzÐSU×S]ÑS]ÐG]ÑA^õ 1r+   