
    h                     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          Q/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/coco.pyr   CocoDetection.__init__   sD     	9G)M	tyy~~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    yy!!"%a(5zz"'',,tyy$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&    yy!!$))"5"5b"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    %%%B4;-yYZZXXe_  $""2&??& OOE:ME}r#   c                 ,    [        U R                  5      $ r1   )lenr   )r   s    r!   __len__CocoDetection.__len__>   s    488}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ekk H;s ;tCy ; sCx   r#   r   c                   >   ^  \ rS rSrSrS\S\\   4U 4S jjrSr	U =r
$ )CocoCaptionsB   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*B3I*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tCy 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#   