
    ,}h                    z    d dl mZ d dlZd dlmZ d dlmZ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)Path)AnyCallableOptionalTupleUnion   )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 (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
            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                 a/var/www/html/test/engine/venv/lib/python3.12/site-packages/torchvision/datasets/fgvc_aircraft.pyr#   zFGVCAircraft.__init__+   s+    	EUV$UG5YZ!/02W"
 '',,tyy2GHNN!!#\]]'',,OO)( 3 $$	&
 /3' 	81567TDJJL7DL	8 !T\\5T\\9J3K!LMGGLL&(Kggll4??FgdF\F\E]]^_c_j_j^kko<pq+s# 	Cq C)-););C)C&
J!!((6GJ<W[I\)]^##D$5$5j$ABC	C 	C 8	8 	8	C 	Cs+   I1!I,8I1BI>,I11I;>Jc                ,    t        | j                        S N)r4   r6   r9   s    rC   __len__zFGVCAircraft.__len__[   s    4$$%%    c                   | j                   |   | j                  |   }}t        j                  j	                  |      j                  d      }| j                  r| j                  |      }| j                  r| j                  |      }||fS )NRGB)r6   r7   PILImager.   convertr   r   )r9   idx
image_filelabelimages        rC   __getitem__zFGVCAircraft.__getitem__^   st     --c2DLL4EE
		z*2259>>NN5)E  ))%0Ee|rH   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)   rF   s    rC   r+   zFGVCAircraft._downloadj   s%     $TYY		:rH   c                    t         j                  j                  | j                        xr) t         j                  j	                  | j                        S rE   )r&   r'   existsr*   isdirrF   s    rC   r,   zFGVCAircraft._check_existsr   s/    ww~~doo.Q277==3QQrH   )r   r   NNF)r)   zUnion[str, Path]r   strr   rX   r   Optional[Callable]r   rY   r:   boolreturnNone)r[   int)rN   r]   r[   zTuple[Any, Any])r[   r\   )r[   rZ   )__name__
__module____qualname____doc__rT   r#   rG   rR   r+   r,   __classcell__)rB   s   @rC   r   r      s    6 eD
   )(,/3.C.C .C 	.C
 &.C -.C .C 
.C`&
;RrH   r   )
__future__r   r&   pathlibr   typingr   r   r   r   r	   	PIL.ImagerK   utilsr   r   visionr   r    rH   rC   <module>rj      s-    " 	  8 8  ? !fR= fRrH   