ó
    Eñiù  ã                   ót   • S SK rS SKJr  S SKJrJrJrJr  S SK	J
r
  SSKJr   " S S\5      r " S	 S
\5      rg)é    N)ÚPath)ÚAnyÚCallableÚOptionalÚUnion)ÚImageé   )ÚVisionDatasetc                   óÖ   ^ • \ 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	\\   4S jrS\S	\\\4   4S jrS	\4S jrSrU =r$ )ÚCocoDetectioné
   a8  `MS Coco Detection <https://cocodataset.org/#detection-2016>`_ Dataset.

It requires `pycocotools <https://github.com/ppwwyyxx/cocoapi>`_ to be installed,
which could be installed via ``pip install pycocotools`` or ``conda install conda-forge::pycocotools``.

Args:
    root (str or ``pathlib.Path``): Root directory where images are downloaded to.
    annFile (string): Path to json annotation file.
    transform (callable, optional): A function/transform that takes in a PIL image
        and returns a transformed version. E.g, ``transforms.PILToTensor``
    target_transform (callable, optional): A function/transform that takes in the
        target and transforms it.
    transforms (callable, optional): A function/transform that takes input sample and its target as entry
        and returns a transformed version.
NÚrootÚannFileÚ	transformÚtarget_transformÚ
transformsÚreturnc                 óÂ   >• [         TU ]  XX45        SSKJn  U" U5      U l        [        [        U R                  R                  R                  5       5      5      U l	        g )Nr   )ÚCOCO)
ÚsuperÚ__init__Úpycocotools.cocor   ÚcocoÚlistÚsortedÚimgsÚkeysÚids)Úselfr   r   r   r   r   r   Ú	__class__s          €ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/coco.pyr   ÚCocoDetection.__init__   sD   ø€ ô 	‰Ñ˜¨9ÔGÝ)á˜“MˆŒ	Üœ˜tŸy™yŸ~™~×2Ñ2Ó4Ó5Ó6ˆ�ó    Úidc                 óÞ   • U R                   R                  U5      S   S   n[        R                  " [        R
                  R                  U R                  U5      5      R                  S5      $ )Nr   Ú	file_nameÚRGB)	r   ÚloadImgsr   ÚopenÚosÚpathÚjoinr   Úconvert)r   r$   r+   s      r!   Ú_load_imageÚCocoDetection._load_image)   sM   € Ø�y‰y×!Ñ! "Ó% aÑ(¨Ñ5ˆÜ�zŠzœ"Ÿ'™'Ÿ,™, t§y¡y°$Ó7Ó8×@Ñ@ÀÓGÐGr#   c                 ój   • U R                   R                  U R                   R                  U5      5      $ ©N)r   ÚloadAnnsÚ	getAnnIds)r   r$   s     r!   Ú_load_targetÚCocoDetection._load_target-   s&   € Ø�y‰y×!Ñ! $§)¡)×"5Ñ"5°bÓ"9Ó:Ð:r#   Úindexc                 ó  • [        U[        5      (       d  [        S[        U5       S35      eU R                  U   nU R                  U5      nU R                  U5      nU R                  b  U R                  X45      u  p4X44$ )Nz#Index must be of type integer, got z	 instead.)Ú
isinstanceÚintÚ
ValueErrorÚtyper   r.   r4   r   )r   r6   r$   ÚimageÚtargets        r!   Ú__getitem__ÚCocoDetection.__getitem__0   sw   € ä˜%¤×%Ñ%ÜÐBÄ4ÈÃ;À-ÈyÐYÓZÐZà�X‰X�e‰_ˆØ× Ñ  Ó$ˆØ×"Ñ" 2Ó&ˆà�?‰?Ñ&Ø ŸO™O¨EÓ:‰MˆEàˆ}Ðr#   c                 ó,   • [        U R                  5      $ r1   )Úlenr   )r   s    r!   Ú__len__ÚCocoDetection.__len__>   s   € Ü�4—8‘8‹}Ðr#   )r   r   )NNN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ústrr   r   r   r   r9   r   r.   r   r   r4   Útupler>   rB   Ú__static_attributes__Ú__classcell__©r    s   @r!   r   r   
   sÌ   ø† ñð( )-Ø/3Ø)-ñ7à�C˜�IÑð7ð ð7ð ˜HÑ%ð	7ð
 # 8Ñ,ð7ð ˜XÑ&ð7ð 
÷7ð 7ðH˜cð H e§k¡kô Hð;˜sð ; t¨C¡yô ;ð ð ¨¨s°C¨x©ô ð˜÷ ò r#   r   c                   ó>   ^ • \ rS rSrSrS\S\\   4U 4S jjrSr	U =r
$ )ÚCocoCaptionséB   aß  `MS Coco Captions <https://cocodataset.org/#captions-2015>`_ Dataset.

It requires `pycocotools <https://github.com/ppwwyyxx/cocoapi>`_ to be installed,
which could be installed via ``pip install pycocotools`` or ``conda install conda-forge::pycocotools``.

Args:
    root (str or ``pathlib.Path``): Root directory where images are downloaded to.
    annFile (string): Path to json annotation file.
    transform (callable, optional): A function/transform that  takes in a PIL image
        and returns a transformed version. E.g, ``transforms.PILToTensor``
    target_transform (callable, optional): A function/transform that takes in the
        target and transforms it.
    transforms (callable, optional): A function/transform that takes input sample and its target as entry
        and returns a transformed version.

Example:

    .. code:: python

        import torchvision.datasets as dset
        import torchvision.transforms as transforms
        cap = dset.CocoCaptions(root = 'dir where images are',
                                annFile = 'json annotation file',
                                transform=transforms.PILToTensor())

        print('Number of samples: ', len(cap))
        img, target = cap[3] # load 4th sample

        print("Image Size: ", img.size())
        print(target)

    Output: ::

        Number of samples: 82783
        Image Size: (3L, 427L, 640L)
        [u'A plane emitting smoke stream flying over a mountain.',
        u'A plane darts across a bright blue sky behind a mountain covered in snow',
        u'A plane leaves a contrail above the snowy mountain top.',
        u'A mountain that has a plane flying overheard in the distance.',
        u'A mountain view with a plume of smoke in the background']

r$   r   c                 óR   >• [         TU ]  U5       Vs/ s H  o"S   PM	     sn$ s  snf )NÚcaption)r   r4   )r   r$   Úannr    s      €r!   r4   ÚCocoCaptions._load_targetn   s)   ø€ Ü*/©'Ñ*>¸rÔ*BÓCÒ*B 3�I”Ñ*BÑCÐCùÒCs   “$© )rD   rE   rF   rG   rH   r9   r   rI   r4   rK   rL   rM   s   @r!   rO   rO   B   s)   ø† ñ)ðVD˜sð D t¨C¡y÷ Dõ Dr#   rO   )Úos.pathr*   Úpathlibr   Útypingr   r   r   r   ÚPILr   Úvisionr
   r   rO   rU   r#   r!   Ú<module>r[      s2   ðÛ Ý ß 1Ó 1å å !ô5�Mô 5ôp-D�=õ -Dr#   