
    kh                    ~    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m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   )default_loader)download_and_extract_archiveverify_str_arg)VisionDatasetc                  t     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variantNFc           
     0   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   zxY w# 1 sw Y   || _        y xY w)N)	transformtarget_transformsplit)trainvalr   testannotation_level)r   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loader)selfr*   r   r   r   r   downloadr:   annotation_fileflineimage_data_folderlabels_file
image_name
label_name	__class__s                  ^/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/fgvc_aircraft.pyr$   zFGVCAircraft.__init__.   s1    	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
  8	8 	8	C
 s+   I8!I38I8BJ3I88JJc                ,    t        | j                        S N)r5   r7   r;   s    rE   __len__zFGVCAircraft.__len__`   s    4$$%%    c                    | j                   |   | j                  |   }}| j                  |      }| j                  r| j                  |      }| j                  r| j	                  |      }||fS rG   )r7   r8   r:   r   r   )r;   idx
image_filelabelimages        rE   __getitem__zFGVCAircraft.__getitem__c   se     --c2DLL4EE
J'>>NN5)E  ))%0Ee|rJ   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*   rH   s    rE   r,   zFGVCAircraft._downloado   s%     $TYY		:rJ   c                    t         j                  j                  | j                        xr) t         j                  j	                  | j                        S rG   )r'   r(   existsr+   isdirrH   s    rE   r-   zFGVCAircraft._check_existsw   s/    ww~~doo.Q277==3QQrJ   )r*   zUnion[str, Path]r   strr   rV   r   Optional[Callable]r   rW   r<   boolr:   zCallable[[str], Any]returnNone)rY   int)rL   r[   rY   zTuple[Any, Any])rY   rZ   )rY   rX   )__name__
__module____qualname____doc__rR   r   r$   rI   rP   r,   r-   __classcell__)rD   s   @rE   r   r      s    < eD
   )(,/3'500 0 	0
 &0 -0 0 %0 
0d&
;RrJ   r   )
__future__r   r'   pathlibr   typingr   r   r   r   r	   folderr   utilsr   r   visionr   r    rJ   rE   <module>rh      s-    " 	  8 8 " ? !kR= kRrJ   