
    hh                    r    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y)    )annotationsN)Path)AnyCallable   )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           
     ,   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        |      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        |      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   yx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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   downloadr6   annotation_fileflineimage_data_folderlabels_file
image_name
label_name	__class__s                  `/var/www/html/eduruby.in/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 $$	&
 /" 	8a567TDJJL7DL	8 !T\\5T\\9J3K!LMGGLL&(Kggll4??FgdF\F\E]]^_c_j_j^kko<pq+ 	C! C)-););C)C&
J!!((6GJ<W[I\)]^##D$5$5j$ABC	C
  8	8 	8	C
 s+   I6 I17I6BJ1I66J Jc                ,    t        | j                        S N)r1   r3   r7   s    rA   __len__zFGVCAircraft.__len__`   s    4$$%%    c                    | j                   |   | j                  |   }}| j                  |      }| j                  r| j                  |      }| j                  r| j	                  |      }||fS rC   )r3   r4   r6   r   r   )r7   idx
image_filelabelimages        rA   __getitem__zFGVCAircraft.__getitem__c   se     --c2DLL4EE
J'>>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._downloado   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_existsw   s/    ww~~doo.Q277==3QQrF   )r&   z
str | Pathr   strr   rR   r   Callable | Noner   rS   r8   boolr6   zCallable[[str], Any]returnNone)rU   int)rH   rW   rU   ztuple[Any, Any])rU   rV   )rU   rT   )__name__
__module____qualname____doc__rN   r   r    rE   rL   r(   r)   __classcell__)r@   s   @rA   r   r      s    < eD
   )%),0'500 0 	0
 #0 *0 0 %0 
0d&
;RrF   r   )
__future__r   r#   pathlibr   typingr   r   folderr   utilsr	   r
   visionr   r    rF   rA   <module>rd      s*    " 	    " ? !kR= kRrF   