
    PhH                    j    d dl mZ d dlZd dlmZmZmZmZ d dlZ	ddl
mZmZ ddlmZ  G d de      Zy)	    )annotationsN)AnyCallableOptionalTuple   )download_and_extract_archiveverify_str_arg)VisionDatasetc                  n     e Zd ZdZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d	 fdZd
dZddZddZddZ	 xZ
S )FGVCAircrafta  `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 (string): 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 an PIL image
            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.
    zWhttps://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/archives/fgvc-aircraft-2013b.tar.gzc           
        t         |   |||       t        |dd      | _        t        |dd      | _        t
        j                  j                  | j                  d      | _	        |r| j                          | j                         st        d      t
        j                  j                  | j                  dd	d
dd| j                           }t        |d      5 }|D 	cg c]  }	|	j                          c}	| _        d d d        t!        t#        | j                  t%        t'        | j                                          | _        t
        j                  j                  | j                  dd      }
t
        j                  j                  | j                  dd| j                   d| j                   d      }g | _        g | _        t        |d      5 }|D ]  }	|	j                         j/                  dd      \  }}| j*                  j1                  t
        j                  j                  |
| d             | j,                  j1                  | j(                  |           	 d d d        y c c}	w # 1 sw Y   sxY w# 1 sw Y   y xY w)N)	transformtarget_transformsplit)trainvaltrainvaltestannotation_level)variantfamilymanufacturerzfgvc-aircraft-2013bz;Dataset not found. You can use download=True to download itdatazvariants.txtzfamilies.txtzmanufacturers.txtrimagesimages__z.txt r   z.jpg)super__init__r
   _split_annotation_levelospathjoinroot
_data_path	_download_check_existsRuntimeErroropenstripclassesdictziprangelenclass_to_idx_image_files_labelsr   append)selfr'   r   r   r   r   downloadannotation_fileflineimage_data_folderlabels_file
image_name
label_name	__class__s                 mC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/datasets/fgvc_aircraft.pyr!   zFGVCAircraft.__init__*   s    	EUV$UG5YZ!/02W"
 '',,tyy2GHNN!!#\]]'',,OO)( 3 $$	&
 /3'1567QTDJJLQ7DL ( !T\\5T\\9J3K!LMGGLL&(Kggll4??FgdF\F\E]]^_c_j_j^kko<pq+s#q)-););C)C&
J!!((6GJ<W[I\)]^##D$5$5j$AB  $# 8 (' $#s+   I1!I,8I1BI>,I11I;>Jc                ,    t        | j                        S N)r2   r4   r7   s    rA   __len__zFGVCAircraft.__len__Z   s    4$$%%    c                   | j                   |   | j                  |   }}t        j                  j	                  |      j                  d      }| j                  r| j                  |      }| j                  r| j                  |      }||fS )NRGB)r4   r5   PILImager,   convertr   r   )r7   idx
image_filelabelimages        rA   __getitem__zFGVCAircraft.__getitem__]   st     --c2DLL4EE
		z*2259>>NN5)E  ))%0Ee|rF   c                f    | j                         ryt        | j                  | j                         y)zW
        Download the FGVC Aircraft dataset archive and extract it under root.
        N)r*   r	   _URLr'   rD   s    rA   r)   zFGVCAircraft._downloadi   s%     $TYY		:rF   c                    t         j                  j                  | j                        xr) t         j                  j	                  | j                        S rC   )r$   r%   existsr(   isdirrD   s    rA   r*   zFGVCAircraft._check_existsq   s/    ww~~doo.Q277==3QQrF   )r   r   NNF)r'   strr   rV   r   rV   r   Optional[Callable]r   rW   r8   boolreturnNone)rY   int)rL   r[   rY   zTuple[Any, Any])rY   rZ   )rY   rX   )__name__
__module____qualname____doc__rR   r!   rE   rP   r)   r*   __classcell__)r@   s   @rA   r   r      s    6 eD
   )(,/3.C.C .C 	.C
 &.C -.C .C 
.C`&
;RrF   r   )
__future__r   r$   typingr   r   r   r   	PIL.ImagerI   utilsr	   r
   visionr   r    rF   rA   <module>rg      s*    " 	 1 1  ? !fR= fRrF   