ó
    Eñi¯  ã                   óü   • S SK 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  SSKJr   " S S	\5      rS
\S\S\S\
R(                  4S jrS
\S\S\
R(                  4S jrS
\S\S\
R(                  4S jrg)é    N)ÚPath)ÚAnyÚCallableÚOptionalÚUnion)ÚImageé   )Údownload_url)ÚVisionDatasetc                   ój  ^ • \ rS rSrSr/ SQ/ SQ/ SQ/ SQ/ SQ/ SQS	.rS
SSS
SSS.rSSSSSSS.rSSSSSSS.rSr	Sr
Sr   S,S\\\4   S\S\S\\   S \S!S4U 4S" jjjrS#\S!\\R*                  \\\\R*                  4   4   4S$ jrS!\4S% jrS!\4S& jrS!\4S' jrS-S( jrS-S) jrS!\4S* jrS+rU =r $ ).Ú	PhotoTouré   aç  `Multi-view Stereo Correspondence <http://matthewalunbrown.com/patchdata/patchdata.html>`_ Dataset.

.. note::

    We only provide the newer version of the dataset, since the authors state that it

        is more suitable for training descriptors based on difference of Gaussian, or Harris corners, as the
        patches are centred on real interest point detections, rather than being projections of 3D points as is the
        case in the old dataset.

    The original dataset is available under http://phototour.cs.washington.edu/patches/default.htm.


Args:
    root (str or ``pathlib.Path``): Root directory where images are.
    name (string): Name of the dataset to load.
    transform (callable, optional): A function/transform that takes in a PIL image
        and returns a transformed version.
    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.

)z:http://matthewalunbrown.com/patchdata/notredame_harris.zipznotredame_harris.zipÚ 69f8c90f78e171349abdf0307afefe4d)z9http://matthewalunbrown.com/patchdata/yosemite_harris.zipzyosemite_harris.zipÚ a73253d1c6fbd3ba2613c45065c00d46)z8http://matthewalunbrown.com/patchdata/liberty_harris.zipzliberty_harris.zipÚ c731fcfb3abb4091110d0ae8c7ba182c)z,http://icvl.ee.ic.ac.uk/vbalnt/notredame.zipznotredame.zipÚ 509eda8535847b8c0a90bbb210c83484)z+http://icvl.ee.ic.ac.uk/vbalnt/yosemite.zipzyosemite.zipÚ 533b2e8eb7ede31be40abc317b2fd4f0)z*http://icvl.ee.ic.ac.uk/vbalnt/liberty.zipzliberty.zipÚ fdd9152f138ea5ef2091746689176414)Únotredame_harrisÚyosemite_harrisÚliberty_harrisÚ	notredameÚyosemiteÚlibertygž^)Ëß?gq¬‹Ûh ß?g„O¯”eÜ?)r   r   r   r   r   r   g$¹ü‡ôÛÇ?g¡Ö4ï8EÇ?g¹ü‡ôÛ×É?i¿$ ióª	 i,Þ iÃÊ i`á i¯ö )r   r   r   r   r   r   Úbmpzinfo.txtzm50_100000_100000_0.txtNÚrootÚnameÚtrainÚ	transformÚdownloadÚreturnc                 óŠ  >• [         TU ]  XS9  X l        [        R                  R                  U R                  U5      U l        [        R                  R                  U R                  U S35      U l        [        R                  R                  U R                  U S35      U l	        X0l
        U R                  U   U l        U R                  U   U l        U(       a  U R                  5         U R!                  5       (       d  U R#                  5         [$        R&                  " U R                  SS9u  U l        U l        U l        g )N)r   z.zipz.ptT)Úweights_only)ÚsuperÚ__init__r   ÚosÚpathÚjoinr   Údata_dirÚ	data_downÚ	data_filer   ÚmeansÚmeanÚstdsÚstdr    Ú_check_datafile_existsÚcacheÚtorchÚloadÚdataÚlabelsÚmatches)Úselfr   r   r   r   r    Ú	__class__s         €Ú[/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/phototour.pyr%   ÚPhotoTour.__init__Z   sà   ø€ ô 	‰Ñ˜ÐÑ3ØŒ	ÜŸ™Ÿ™ T§Y¡Y°Ó5ˆŒÜŸ™Ÿ™ d§i¡i°D°6¸°Ó?ˆŒÜŸ™Ÿ™ d§i¡i°D°6¸°Ó>ˆŒàŒ
Ø—J‘J˜tÑ$ˆŒ	Ø—9‘9˜T‘?ˆŒæØ�M‰MŒOà×*Ñ*×,Ñ,Ø�J‰JŒLô 05¯zªz¸$¿.¹.ÐW[Ñ/\Ñ,ˆŒ	�4”; ¥ó    Úindexc                 óR  • U R                   (       a/  U R                  U   nU R                  b  U R                  U5      nU$ U R                  U   nU R                  US      U R                  US      pTU R                  b"  U R                  U5      nU R                  U5      nXEUS   4$ )zK
Args:
    index (int): Index

Returns:
    tuple: (data1, data2, matches)
r   r	   é   )r   r4   r   r6   )r7   r<   r4   ÚmÚdata1Údata2s         r9   Ú__getitem__ÚPhotoTour.__getitem__u   s˜   € ð �:�:Ø—9‘9˜UÑ#ˆDØ�~‰~Ñ)Ø—~‘~ dÓ+�ØˆKØ�L‰L˜ÑˆØ—y‘y  1¡‘¨¯	©	°!°A±$©ˆuØ�>‰>Ñ%Ø—N‘N 5Ó)ˆEØ—N‘N 5Ó)ˆEØ˜Q˜q™TÐ!Ð!r;   c                 ón   • [        U R                  (       a  U R                  5      $ U R                  5      $ ©N)Úlenr   r4   r6   ©r7   s    r9   Ú__len__ÚPhotoTour.__len__‰   s#   € Ü §
§
�4—9‘9Ó=Ð=°·±Ó=Ð=r;   c                 óT   • [         R                  R                  U R                  5      $ rE   )r&   r'   Úexistsr+   rG   s    r9   r0   Ú PhotoTour._check_datafile_existsŒ   s   € Ü�w‰w�~‰~˜dŸn™nÓ-Ð-r;   c                 óT   • [         R                  R                  U R                  5      $ rE   )r&   r'   rK   r)   rG   s    r9   Ú_check_downloadedÚPhotoTour._check_downloaded�   s   € Ü�w‰w�~‰~˜dŸm™mÓ,Ð,r;   c                 óF  • U R                  5       (       a  g U R                  5       (       då  U R                  U R                     S   nU R                  U R                     S   nU R                  U R                     S   n[        R
                  R                  U R                  U5      n[        XR                  X#5        SS K	nUR                  US5       nUR                  U R                  5        S S S 5        [        R                  " U5        g g ! , (       d  f       N&= f)Nr   r	   r>   Úr)r0   rN   Úurlsr   r&   r'   r(   r   r
   ÚzipfileÚZipFileÚ
extractallr)   Úunlink)r7   ÚurlÚfilenameÚmd5ÚfpathrS   Úzs          r9   r    ÚPhotoTour.download’   sÒ   € Ø×&Ñ&×(Ñ(Øà×%Ñ%×'Ñ'à—)‘)˜DŸI™IÑ& qÑ)ˆCØ—y‘y §¡Ñ+¨AÑ.ˆHØ—)‘)˜DŸI™IÑ& qÑ)ˆCÜ—G‘G—L‘L §¡¨HÓ5ˆEä˜Ÿi™i¨Ô7ãà—‘ ¨Ô,°Ø—‘˜TŸ]™]Ô+÷ -ô �IŠI�eÕð (÷ -Õ,ús   ÃDÄ
D c                 ó~  • [        U R                  U R                  U R                  U R                     5      [        U R                  U R                  5      [        U R                  U R                  5      4n[        U R                  S5       n[        R                  " X5        S S S 5        g ! , (       d  f       g = f)NÚwb)Úread_image_filer)   Ú	image_extÚlensr   Úread_info_fileÚ	info_fileÚread_matches_filesÚmatches_filesÚopenr+   r2   Úsave)r7   ÚdatasetÚfs      r9   r1   ÚPhotoTour.cache¦   s|   € ô ˜DŸM™M¨4¯>©>¸4¿9¹9ÀTÇYÁYÑ;OÓPÜ˜4Ÿ=™=¨$¯.©.Ó9Ü˜tŸ}™}¨d×.@Ñ.@ÓAð
ˆô �$—.‘. $Ô'¨1Ü�JŠJ�wÔ"÷ (×'Ö'ús   ÂB.Â.
B<c                 ó2   • U R                   SL a  SOSnSU 3$ )NTÚTrainÚTestzSplit: )r   )r7   Úsplits     r9   Ú
extra_reprÚPhotoTour.extra_repr²   s!   € ØŸ:™:¨Ò-‘°6ˆØ˜˜Ð Ð r;   )
r4   r)   r*   r+   r5   r6   r-   r   r/   r   )TNF)r!   N)!Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rR   r,   r.   ra   r`   rc   re   r   Ústrr   Úboolr   r   r%   Úintr2   ÚTensorÚtupler   rB   rH   r0   rN   r    r1   ro   Ú__static_attributes__Ú__classcell__)r8   s   @r9   r   r      sc  ø† ñò2
ò

ò

ò

ò
 xÚtñ-€Dð2 ØØØ"Ø!Ø ñ€Eð ØØØ"Ø!Ø ñ€Dð ØØØ Ø!Ø"ñ€Dð €IØ€IØ-€Mð Ø(,Øñ]à�C˜�IÑð]ð ð]ð ð	]ð
 ˜HÑ%ð]ð ð]ð 
÷]ð ]ð6" ð "¨¨u¯|©|¸UÀ3ÈÈUÏ\É\ÐCYÑ=ZÐ/ZÑ)[ô "ð(>˜ô >ð.¨ô .ð- 4ô -ôô(
#ð!˜C÷ !ò !r;   r   r)   r`   Únr!   c           
      ó  • S[         R                   S[        R                  4S jnS[        S[        S[        [           4S jn/ nU" X5      nU H†  n[         R
                  " U5      n[        SUR                  S5       HR  n	[        SUR                  S5       H4  n
UR                  X©U
S-   U	S-   45      nUR                  U" U5      5        M6     MT     Mˆ     [        R                  " [        R                  " US	U 5      5      $ )
z&Return a Tensor containing the patchesÚ_imgr!   c                 ó„   • [         R                  " U R                  5       [         R                  S9R	                  SS5      $ )z(Convert PIL image type to numpy 2D array)Údtypeé@   )ÚnpÚarrayÚgetdataÚuint8Úreshape)r   s    r9   Ú	PIL2arrayÚ"read_image_file.<locals>.PIL2arrayº   s*   € ä�xŠx˜Ÿ™›¬b¯h©hÑ7×?Ñ?ÀÀBÓGÐGr;   Ú	_data_dirÚ
_image_extc                 óâ   • / n[         R                  " U 5       HI  nUR                  U5      (       d  M  UR                  [         R                  R                  X5      5        MK     [        U5      $ )zFReturn a list with the file names of the images containing the patches)r&   ÚlistdirÚendswithÚappendr'   r(   Úsorted)rŠ   r‹   ÚfilesÚfile_dirs       r9   Ú
find_filesÚ#read_image_file.<locals>.find_files¾   sP   € àˆäŸ
š
 9Ö-ˆHØ× Ñ  ×,Ó,Ø—‘œRŸW™WŸ\™\¨)Ó>Ö?ñ .ô �e‹}Ðr;   r   r‚   N)r   rƒ   Úndarrayrv   Úlistrf   ÚrangeÚheightÚwidthÚcropr�   r2   Ú
ByteTensorr„   )r)   r`   r}   rˆ   r“   ÚpatchesÚ
list_filesrZ   ÚimgÚyÚxÚpatchs               r9   r_   r_   ·   så   € ðHœŸ™ð H¬¯
©
ô Hðœcð ¬sð ´t¼C±yô ð €GÙ˜HÓ0€JãˆÜ�jŠj˜ÓˆÜ�q˜#Ÿ*™* bÖ)ˆAÜ˜1˜cŸi™i¨Ö,�ØŸ™ !¨¨B©°°B±Ð!7Ó8�Ø—‘™y¨Ó/Ö0ó -ó *ñ ô ×ÒœBŸHšH W¨R¨a [Ó1Ó2Ð2r;   rc   c                 ó  • [        [        R                  R                  X5      5       nU Vs/ s H  n[	        UR                  5       S   5      PM!     nnSSS5        [        R                  " W5      $ s  snf ! , (       d  f       N)= f)zbReturn a Tensor containing the list of labels
Read the file and keep only the ID of the 3D point.
r   N)rf   r&   r'   r(   rx   rn   r2   Ú
LongTensor)r)   rc   ri   Úliner5   s        r9   rb   rb   Ó   sb   € ô 
Œb�g‰g�l‰l˜8Ó/Ô	0°AÙ34Ó5²1¨4”#�d—j‘j“l 1‘oÖ&±1ˆÐ5÷ 
1ä×Ò˜FÓ#Ð#ùò 6÷ 
1Õ	0ús   ©A9®&A4ÁA9Á4A9Á9
BÚmatches_filec                 ód  • / n[        [        R                  R                  X5      5       nU HQ  nUR	                  5       nUR                  [        US   5      [        US   5      [        US   US   :H  5      /5        MS     SSS5        [        R                  " U5      $ ! , (       d  f       N$= f)z•Return a Tensor containing the ground truth matches
Read the file and keep only 3D point ID.
Matches are represented with a 1, non matches with a 0.
r   é   r	   é   N)	rf   r&   r'   r(   rn   r�   rx   r2   r£   )r)   r¥   r6   ri   r¤   Ú
line_splits         r9   rd   rd   Ü   s‘   € ð
 €GÜ	Œb�g‰g�l‰l˜8Ó2Ô	3°qÛˆDØŸ™›ˆJØ�N‰NœC 
¨1¡Ó.´°J¸q±MÓ0BÄCÈ
ÐSTÉÐYcÐdeÑYfÑHfÓDgÐhÖiñ ÷ 
4ô ×Ò˜GÓ$Ð$÷	 
4Õ	3ús   «AB!Â!
B/)r&   Úpathlibr   Útypingr   r   r   r   Únumpyrƒ   r2   ÚPILr   Úutilsr
   Úvisionr   r   rv   rx   ry   r_   rb   rd   © r;   r9   Ú<module>r±      s�   ðÛ 	Ý ß 1Ó 1ã Û Ý å Ý !ôg!�ô g!ðT3˜cð 3¨cð 3°cð 3¸e¿l¹lô 3ð8$˜Sð $¨Sð $°U·\±\ô $ð
% ð 
%°Cð 
%¸E¿L¹Lõ 
%r;   