
    Yhh                    z    d dl mZ d dlZd dlmZ d dlmZmZ ddlm	Z	 ddl
mZmZ ddlmZ  G d	 d
e          ZdS )    )annotationsN)Path)AnyCallable   )default_loader)download_and_extract_archiveverify_str_arg)VisionDatasetc                  V     e Zd ZdZdZdddddefd fdZddZddZd dZ	d!dZ
 xZS )"FGVCAircrafta2  `FGVC Aircraft <https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/>`_ Dataset.

    The dataset contains 10,000 images of aircraft, with 100 images for each of 100
    different aircraft model variants, most of which are airplanes.
    Aircraft models are organized in a three-levels hierarchy. The three levels, from
    finer to coarser, are:

    - ``variant``, e.g. Boeing 737-700. A variant collapses all the models that are visually
        indistinguishable into one class. The dataset comprises 100 different variants.
    - ``family``, e.g. Boeing 737. The dataset comprises 70 different families.
    - ``manufacturer``, e.g. Boeing. The dataset comprises 30 different manufacturers.

    Args:
        root (str or ``pathlib.Path``): Root directory of the FGVC Aircraft dataset.
        split (string, optional): The dataset split, supports ``train``, ``val``,
            ``trainval`` and ``test``.
        annotation_level (str, optional): The annotation level, supports ``variant``,
            ``family`` and ``manufacturer``.
        transform (callable, optional): A function/transform that takes in a PIL image or torch.Tensor, depends on the given loader,
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        target_transform (callable, optional): A function/transform that takes in the
            target and transforms it.
        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.
        loader (callable, optional): A function to load an image given its path.
            By default, it uses PIL as its image loader, but users could also pass in
            ``torchvision.io.decode_image`` for decoding image data into tensors directly.
    zWhttps://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/archives/fgvc-aircraft-2013b.tar.gztrainvalvariantNFroot
str | Pathsplitstrannotation_level	transformCallable | Nonetarget_transformdownloadboolloaderCallable[[str], Any]returnNonec           
     (   t                                          |||           t          |dd          | _        t          |dd          | _        t
          j                            | j        d          | _	        |r| 
                                 |                                 st          d          t
          j                            | j	        dd	d
dd| j                           }t          |          5 }	d |	D             | _        d d d            n# 1 swxY w Y   t          t!          | j        t#          t%          | j                                                | _        t
          j                            | j	        dd          }
t
          j                            | j	        dd| j         d| j         d          }g | _        g | _        t          |          5 }	|	D ]}|                                                    dd          \  }}| j                            t
          j                            |
| d                     | j                            | j        |                    	 d d d            n# 1 swxY w Y   || _        d S )N)r   r   r   )trainvalr   testr   )r   familymanufacturerzfgvc-aircraft-2013bz;Dataset not found. You can use download=True to download itdatazvariants.txtzfamilies.txtzmanufacturers.txtc                6    g | ]}|                                 S  )strip).0lines     t/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torchvision/datasets/fgvc_aircraft.py
<listcomp>z)FGVCAircraft.__init__.<locals>.<listcomp>O   s     777TDJJLL777    imagesimages__z.txt r   z.jpg)super__init__r
   _split_annotation_levelospathjoinr   
_data_path	_download_check_existsRuntimeErroropenclassesdictziprangelenclass_to_idx_image_files_labelsr'   r   appendr   )selfr   r   r   r   r   r   r   annotation_filefimage_data_folderlabels_filer)   
image_name
label_name	__class__s                  r*   r2   zFGVCAircraft.__init__.   s    	EUVVV$UG5YZZ!/02W"
 "
 ',,ty2GHH 	NN!!## 	^\]]]',,O)( 3  $	&
 
 /"" 	8a77Q777DL	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 !T\5T\9J9J3K3K!L!LMMGLL&(KKgll4?F<pdF\<p<p_c_j<p<p<pqq+ 	C! C C)-););C)C)C&
J!((6GJI\I\I\)])]^^^##D$5j$ABBBBC	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C
 s%   9DDD"BJ  JJintc                *    t          | j                  S N)rA   rC   rF   s    r*   __len__zFGVCAircraft.__len__`   s    4$%%%r,   idxtuple[Any, Any]c                    | j         |         | j        |         }}|                     |          }| j        r|                     |          }| j        r|                     |          }||fS rP   )rC   rD   r   r   r   )rF   rS   
image_filelabelimages        r*   __getitem__zFGVCAircraft.__getitem__c   sn     -c2DL4EE
J''> 	*NN5))E  	1))%00Ee|r,   c                f    |                                  rdS t          | j        | j                   dS )zW
        Download the FGVC Aircraft dataset archive and extract it under root.
        N)r:   r	   _URLr   rQ   s    r*   r9   zFGVCAircraft._downloado   s7      	F$TY	:::::r,   c                    t           j                            | j                  o#t           j                            | j                  S rP   )r5   r6   existsr8   isdirrQ   s    r*   r:   zFGVCAircraft._check_existsw   s-    w~~do..Q27==3Q3QQr,   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   rN   )rS   rN   r   rT   )r   r   )r   r   )__name__
__module____qualname____doc__r[   r   r2   rR   rY   r9   r:   __classcell__)rM   s   @r*   r   r      s         < eD
   )%),0'50 0 0 0 0 0 0d& & & &
 
 
 
; ; ; ;R R R R R R R Rr,   r   )
__future__r   r5   pathlibr   typingr   r   folderr   utilsr	   r
   visionr   r   r&   r,   r*   <module>rj      s    " " " " " " 				                       " " " " " " ? ? ? ? ? ? ? ? ! ! ! ! ! !kR kR kR kR kR= kR kR kR kR kRr,   