ó
    Eñi  ã                   ó‚   • S SK r 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Jr  SSKJrJrJr  SSKJr   " S S	\5      rg)
é    N)ÚPath)ÚAnyÚCallableÚOptionalÚUnion)ÚImageé   )Údownload_and_extract_archiveÚdownload_urlÚverify_str_arg)ÚVisionDatasetc                   ó   ^ • \ rS rSrSrSrSr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$                  4S jrS\S\R*                  4S jrS\S\\\4   4S jrS\4S jrS\4S jrSrU =r$ )Ú	SBDataseté   a,  `Semantic Boundaries Dataset <http://home.bharathh.info/pubs/codes/SBD/download.html>`_

The SBD currently contains annotations from 11355 images taken from the PASCAL VOC 2011 dataset.

.. note ::

    Please note that the train and val splits included with this dataset are different from
    the splits in the PASCAL VOC dataset. In particular some "train" images might be part of
    VOC2012 val.
    If you are interested in testing on VOC 2012 val, then use `image_set='train_noval'`,
    which excludes all val images.

.. warning::

    This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.

Args:
    root (str or ``pathlib.Path``): Root directory of the Semantic Boundaries Dataset
    image_set (string, optional): Select the image_set to use, ``train``, ``val`` or ``train_noval``.
        Image set ``train_noval`` excludes VOC 2012 val images.
    mode (string, optional): Select target type. Possible values 'boundaries' or 'segmentation'.
        In case of 'boundaries', the target is an array of shape `[num_classes, H, W]`,
        where `num_classes=20`.
    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.
    transforms (callable, optional): A function/transform that takes input sample and its target as entry
        and returns a transformed version. Input sample is PIL image and target is a numpy array
        if `mode='boundaries'` or PIL image if `mode='segmentation'`.
zchttps://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgzÚ 82b4d87ceb2ed10f6038a1cba92111cbzbenchmark.tgzz4https://www.cs.cornell.edu/~bharathh/train_noval.txtztrain_noval.txtÚ 79bff800c5f0b1ec6b21080a3c066722NÚrootÚ	image_setÚmodeÚdownloadÚ
transformsÚreturnc                 ó  >•  SSK Jn  X`l        [
        TU ]  X5        [        USS5      U l        [        USS5      U l	        SU l
        U R                  n[        R                  R                  US	5      n[        R                  R                  US
5      n	U(       aØ  [        U R                   U R                  U R"                  U R$                  S9  [        R                  R                  U R                  SS5      n
S H8  n[        R                  R                  X«5      n[&        R(                  " XÇ5        M:     U R                  S:X  a+  [+        U R,                  XpR.                  U R0                  5        [        R                  R3                  U5      (       d  [	        S5      e[        R                  R                  XrR5                  S5      S-   5      n[7        [        R                  R                  U5      5       nUR9                  5        Vs/ s H  oÿR;                  5       PM     nnS S S 5        W Vs/ s H%  n[        R                  R                  X�S-   5      PM'     snU l        U Vs/ s H%  n[        R                  R                  XŸS-   5      PM'     snU l        U R                  S:X  a  U R@                  U l"        g U RB                  U l"        g ! [         a    [	        S5      ef = fs  snf ! , (       d  f       NÐ= fs  snf s  snf )Nr   )ÚloadmatzQScipy is not found. This dataset needs to have scipy installed: pip install scipyr   )ÚtrainÚvalÚtrain_novalr   )ÚsegmentationÚ
boundariesé   ÚimgÚcls)ÚfilenameÚmd5Úbenchmark_RELEASEÚdataset)r"   r!   Úinstz	train.txtzval.txtr   zHDataset not found or corrupted. You can use download=True to download itÚ
z.txtz.jpgz.matr   )#Úscipy.ior   Ú_loadmatÚImportErrorÚRuntimeErrorÚsuperÚ__init__r   r   r   Únum_classesr   ÚosÚpathÚjoinr
   Úurlr#   r$   ÚshutilÚmover   Úvoc_train_urlÚvoc_split_filenameÚvoc_split_md5ÚisdirÚrstripÚopenÚ	readlinesÚstripÚimagesÚmasksÚ_get_segmentation_targetÚ_get_boundaries_targetÚ_get_target)Úselfr   r   r   r   r   r   Úsbd_rootÚ	image_dirÚmask_dirÚextracted_ds_rootÚfÚold_pathÚsplit_fÚfhÚxÚ
file_namesÚ	__class__s                    €ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/sbd.pyr.   ÚSBDataset.__init__5   s;  ø€ ð	tÝ(à#ŒMô 	‰Ñ˜Ô*Ü'¨	°;Ð@_Ó`ˆŒÜ" 4¨Ð1OÓPˆŒ	ØˆÔà—9‘9ˆÜ—G‘G—L‘L ¨5Ó1ˆ	Ü—7‘7—<‘< ¨%Ó0ˆæÜ(¨¯©°4·9±9ÀtÇ}Á}ÐZ^×ZbÑZbÒcÜ "§¡§¡¨T¯Y©YÐ8KÈYÓ WÐÛC�ÜŸ7™7Ÿ<™<Ð(9Ó=�Ü—’˜HÖ/ñ Dð �~‰~ Ó.ä˜T×/Ñ/°×;RÑ;RÐTX×TfÑTfÔgä�w‰w�}‰}˜X×&Ñ&ÜÐiÓjÐjä—'‘'—,‘,˜x×)9Ñ)9¸$Ó)?À&Ñ)HÓIˆä”"—'‘'—,‘,˜wÓ'Ô(¨BØ-/¯\©\¬^Ó<ª^¨Ÿ'™'ž)©^ˆJÐ<÷ )ñ EOÓOÂJ¸q”r—w‘w—|‘| I°6©zÖ:ÁJÑOˆŒÙBLÓMÂ*¸Q”b—g‘g—l‘l 8°©ZÖ8Á*ÑMˆŒ
à<@¿I¹IÈÓ<W˜4×8Ñ8ˆÕÐ]a×]xÑ]xˆÕøôC ó 	tÜÐrÓsÐsð	tüò8 =÷ )Õ(üò PùÚMs5   ƒK Ç<K4ÈK/È(K4È6,LÉ.,L
ËK,Ë/K4Ë4
LÚfilepathc                 óh   • U R                  U5      n[        R                  " US   S   S   S   5      $ )NÚGTclsr   ÚSegmentation)r*   r   Ú	fromarray)rC   rQ   Úmats      rO   r@   Ú"SBDataset._get_segmentation_targete   s1   € Ø�m‰m˜HÓ%ˆÜ�Š˜s 7™|¨A™¨~Ñ>¸qÑAÓBÐBó    c           
      ó  • U R                  U5      n[        R                  " [        U R                  5       Vs/ s H8  n[        R
                  " US   S   S   S   U   S   R                  5       SS9PM:     snSS9$ s  snf )NrS   r   Ú
Boundaries)Úaxis)r*   ÚnpÚconcatenateÚranger/   Úexpand_dimsÚtoarray)rC   rQ   rV   Úis       rO   rA   Ú SBDataset._get_boundaries_targeti   sy   € Ø�m‰m˜HÓ%ˆÜ�~Š~Ü_dÐei×euÑeuÔ_vÓwÒ_vÐZ[ŒR�^Š^˜C ™L¨™O¨LÑ9¸!Ñ<¸QÑ?ÀÑB×JÑJÓLÐSTÔUÑ_vÑwØñ
ð 	
ùÚws   ¹?A>Úindexc                 óè   • [         R                  " U R                  U   5      R                  S5      nU R	                  U R
                  U   5      nU R                  b  U R                  X#5      u  p#X#4$ )NÚRGB)r   r;   r>   ÚconvertrB   r?   r   )rC   rc   r!   Útargets       rO   Ú__getitem__ÚSBDataset.__getitem__p   s_   € Ü�jŠj˜Ÿ™ UÑ+Ó,×4Ñ4°UÓ;ˆØ×!Ñ! $§*¡*¨UÑ"3Ó4ˆà�?‰?Ñ&ØŸ/™/¨#Ó6‰KˆCàˆ{ÐrX   c                 ó,   • [        U R                  5      $ )N)Úlenr>   )rC   s    rO   Ú__len__ÚSBDataset.__len__y   s   € Ü�4—;‘;ÓÐrX   c                 ó`   • SS/nSR                  U5      R                  " S0 U R                  D6$ )NzImage set: {image_set}zMode: {mode}r(   © )r2   ÚformatÚ__dict__)rC   Úliness     rO   Ú
extra_reprÚSBDataset.extra_repr|   s-   € Ø)¨>Ð:ˆØ�y‰y˜Ó×&Ò&Ñ7¨¯©Ñ7Ð7rX   )rB   r*   r   r>   r?   r   r/   )r   r   FN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r3   r$   r#   r6   r7   r8   r   Ústrr   Úboolr   r   r.   r   r@   r\   ÚndarrayrA   ÚintÚtupler   rh   rl   rs   Ú__static_attributes__Ú__classcell__)rN   s   @rO   r   r      sü   ø† ñð> p€CØ
,€CØ€HàJ€MØ*ÐØ6€Mð
 !Ø ØØ)-ñ.yà�C˜�IÑð.yð ð.yð ð	.yð
 ð.yð ˜XÑ&ð.yð 
÷.yð .yð`C°ð C¸¿¹ô Cð
¨sð 
°r·z±zô 
ð ð ¨¨s°C¨x©ô ð ˜ô  ð8˜C÷ 8ò 8rX   r   )r0   r4   Úpathlibr   Útypingr   r   r   r   Únumpyr\   ÚPILr   Úutilsr
   r   r   Úvisionr   r   ro   rX   rO   Ú<module>r‡      s1   ðÛ 	Û Ý ß 1Ó 1ã Ý ç MÑ MÝ !ôq8�õ q8rX   