
    hR                     \   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       Z/var/www/auris/envauris/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5a89~~d..u5a89????4??5#9:D**(,%o"&%))D??&04D0b-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#    {{--tfqj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ell1J+K ' C  $ $r2v $.% %:# :%++"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   XS-      //-  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ug4EFy+<VW'0F':'7#DzH$:%.	I&+w&6
EI)I5JJ/#DZ-?'-I)J$KL
s:23A$$*-E9J)K(LL$ 4 G#OOvd3y7H77R3S.T'UUO 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* *r2v *$C $BJJ $ $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ug4EFDzK'55=9c$"2Z"?@ABc$"2Z"?@ABg#l  g/JD$. 0 G$T#dZ.?*.L*M%NODO 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* *r2v *DC DE"**bjj2H,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:ug4DEDzN*S!89:;tCv 789:6ww~~d455#  ZZD$: ;288L
s5z"A!}H X]8WX=EH:-  fQUmVAEAI5F%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U39- Ic IQYZbQc Ios I I.* *r2v *$C $BJJ $ $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[        X5       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\xtH~	9FBS\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ug4EFy+<VW()()');<
 	 	vx6OP'-'767#fXDz,,1
,5,=,=fz,Z(IvyS)9E)AE)I%J KLJU*UUJtC~(=(E(M$NOPI]S\]]IY'K 
 (+:'A#	SW)<%= >?tC7(:$;<=s5zA~.A M1((fQiA-G,HH(E!H:5"k1((fQUmVAY-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* *r2v *$C $BJJ $ $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
[        X5       H  u  pU =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ug4EFDzF"G 9tC~(=
(JPWX[}\bMc(c$defS)<y)HgVY]Z`Ka)a%b cds5zA~.AOOz1O$$&)VE])C(DD$ / % T#d-=&=	&II&U"VWXGT#d-=&=	&II&U"VWXG"%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"**bjj2H,I D* *r2v * *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5      n[        [        R                  " USSS9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
ValueErrorrQ   reshape	transpose)r,   fmagicwhrG   s         r)   r}   r}     s     
i	!As!,446GHIIAuA./AuA./{{1e1q5195||A!$..q!Q7 
		s   B2C		
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GN*2A2q!84nQ1W6M/5LB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;;Xbjj%98BJJ;OOP
5;;Xbjj%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rzzSUS]S]G]A^ 1r+   