
    QЦiT                     |    S SK rS SKJr  S SKJrJr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ListOptionalTuple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
   a  `MS Coco Detection <https://cocodataset.org/#detection-2016>`_ Dataset.

It requires the `COCO API to be installed <https://github.com/pdollar/coco/tree/master/PythonAPI>`_.

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          X/var/www/html/ai-image-ml/venv/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    r0   r6   r   )r!   r8   r&   imagetargets        r#   __getitem__CocoDetection.__getitem__/   sw    %%%B4;-yYZZXXe_  $""2&??& OOE:ME}r%   c                 ,    [        U R                  5      $ r3   )lenr    )r!   s    r#   __len__CocoDetection.__len__=   s    488}r%   )r   r    )NNN)__name__
__module____qualname____firstlineno____doc__r	   strr   r   r   r   r;   r
   r0   r   r   r6   r   r@   rD   __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
$ )CocoCaptionsA   a  `MS Coco Captions <https://cocodataset.org/#captions-2015>`_ Dataset.

It requires the `COCO API to be installed <https://github.com/pdollar/coco/tree/master/PythonAPI>`_.

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   r6   )r!   r&   annr"   s      r#   r6   CocoCaptions._load_targetl   s)    */'*>r*BC*B3I*BCCCs   $ )rF   rG   rH   rI   rJ   r;   r   rK   r6   rL   rM   rN   s   @r#   rP   rP   A   s)    (TDs DtCy D Dr%   rP   )os.pathr,   pathlibr   typingr   r   r   r   r   r	   PILr
   visionr   r   rP   rV   r%   r#   <module>r\      s2      > >  !4M 4n,D= ,Dr%   