
    QЦi&                         S SK r S SKr S SKJr  S SKJrJrJrJrJ	r	J
r
Jr  S SKJr  SSKJrJr  SSKJr  / SQrS	S
SSSSS.rSSSSSSS.r " S S\5      rg)    N)Path)AnyCallableDictListOptionalTupleUnion)Image   )download_and_extract_archiveverify_str_arg)VisionDataset)kingdomphylumclassorderfamilygenuszRhttps://ml-inat-competition-datasets.s3.amazonaws.com/2017/train_val_images.tar.gzzOhttps://ml-inat-competition-datasets.s3.amazonaws.com/2018/train_val2018.tar.gzzOhttps://ml-inat-competition-datasets.s3.amazonaws.com/2019/train_val2019.tar.gzzGhttps://ml-inat-competition-datasets.s3.amazonaws.com/2021/train.tar.gzzLhttps://ml-inat-competition-datasets.s3.amazonaws.com/2021/train_mini.tar.gzzEhttps://ml-inat-competition-datasets.s3.amazonaws.com/2021/val.tar.gz)201720182019
2021_train2021_train_mini
2021_valid 7c784ea5e424efaec655bd392f87301f b1c6952ce38f31868cc50ea72d066cc3 c60a6e2962c9b8ccbd458d12c8582644 e0526d53c7f7b2e3167b2b43bb2690ed db6ed8330e634445efc8fec83ae81442 f6f6e0e242e3d4c9569ba56400938afcc                      ^  \ rS rSrSr     SS\\\4   S\S\\\   \4   S\	\
   S\	\
   S	\S
S4U 4S jjjrSS jrSS jrS\S
\\\4   4S jrS
\4S jrS\S\S
\4S jrS
\4S jrSS jrSrU =r$ )INaturalist    a  `iNaturalist <https://github.com/visipedia/inat_comp>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where the image files are stored.
        This class does not require/use annotation files.
    version (string, optional): Which version of the dataset to download/use. One of
        '2017', '2018', '2019', '2021_train', '2021_train_mini', '2021_valid'.
        Default: `2021_train`.
    target_type (string or list, optional): Type of target to use, for 2021 versions, one of:

        - ``full``: the full category (species)
        - ``kingdom``: e.g. "Animalia"
        - ``phylum``: e.g. "Arthropoda"
        - ``class``: e.g. "Insecta"
        - ``order``: e.g. "Coleoptera"
        - ``family``: e.g. "Cleridae"
        - ``genus``: e.g. "Trichodes"

        for 2017-2019 versions, one of:

        - ``full``: the full (numeric) category
        - ``super``: the super category, e.g. "Amphibians"

        Can also be a list to output a tuple with all specified target types.
        Defaults to ``full``.
    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.
Nrootversiontarget_type	transformtarget_transformdownloadreturnc           	        > [        US[        R                  5       5      U l        [        TU ]  [        R                  R                  X5      XES9  [        R                  " USS9  U(       a  U R                  5         U R                  5       (       d  [        S5      e/ U l        0 U l        / U l        [!        U["        5      (       d  U/nU R                  S S S:X  a<  U Vs/ s H  n[        USS	/[$        Q75      PM     snU l        U R)                  5         O3U Vs/ s H  n[        USS
5      PM     snU l        U R+                  5         / U l        [/        U R                  5       Hh  u  p[        R0                  " [        R                  R                  U R2                  U	5      5      n
U
 H  nU R,                  R5                  X45        M!     Mj     g s  snf s  snf )Nr&   )r(   r)   T)exist_okzHDataset not found or corrupted. You can use download=True to download it   2021r'   full)r0   super)r   DATASET_URLSkeysr&   r1   __init__ospathjoinmakedirsr*   _check_existsRuntimeErrorall_categoriescategories_indexcategories_map
isinstancelistCATEGORIES_2021r'   
_init_2021_init_pre2021index	enumeratelistdirr%   append)selfr%   r&   r'   r(   r)   r*   t	dir_indexdir_namefilesfname	__class__s               _/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/inaturalist.pyr4   INaturalist.__init__C   s    &gy,:K:K:MNd4	m
D4(MMO!!##ijj)+ <> 57+t,,&-K<<v%fqrfqabq-&A[?A[ \fqrDOO]hi]hXYq-AR S]hiD  -/
#,T-@-@#AIJJrww||DIIx@AE

!!9"45  $B  s  js   !GGc                    [        [        R                  " U R                  5      5      U l        [
         Vs0 s H  o0 _M     snU l        [        U R                  5       H  u  p#UR                  S5      n[        U5      S:w  a  [        SU S35      eUS   US :w  a  [        SUS    SUS 35      e0 n[        [
        US	S
 5       HW  u  pgXpR                  U   ;   a  U R                  U   U   nO)[        U R                  U   5      nXR                  U   U'   XU'   MY     U R                  R                  U5        M     gs  snf )zInitialize based on 2021 layout_   zUnexpected category name z, wrong number of piecesr   05dzUnexpected category id z, expecting r      N)sortedr5   rE   r%   r;   r@   r<   rD   splitlenr:   zipr=   rF   )	rG   krI   rJ   piecescat_mapcatnamecat_ids	            rN   rA   INaturalist._init_2021p   sD    %RZZ		%:; 1@ @1B @#,T-@-@#AI^^C(F6{a"%>xjH`#abbayyo."%<VAYK|T]^aSb#cddG &1+>	0055!2237=F !6!6s!;<F7=))#.t4% ? &&w/ $B !As   Ec           	         S0 0U l         Sn[        [        R                  " U R                  5      5      n[        U5       GH`  u  p4X0R                   S   U'   [        [        R                  " [        R                  R                  U R                  U5      5      5      nU H  nU R                  S:X  a  UnUS-  nO [        U5      nU[        U R                  5      :  a]  [        U R                  5      nU R                  R                  0 /Xx-
  S-   -  5        U R                  R                  S/Xx-
  S-   -  5        U R                  U   (       a  [        SU 35      eSU0U R                  U'   [        R                  R                  XF5      U R                  U'   M     GMc     [        U R                  5       H  u  pU
(       a  M  [        SU	 35      e   g	! [         a    [        SU 35      ef = f)
z$Initialize based on 2017-2019 layoutr1   r   r   r   z!Unexpected non-numeric dir name:  zDuplicate category zMissing category N)r<   rU   r5   rE   r%   rD   r6   r7   r&   int
ValueErrorr:   rW   r=   extendr;   )rG   	cat_indexsuper_categoriessindexscatsubcategoriessubcatsubcat_iold_lencindexcs              rN   rB   INaturalist._init_pre2021   s    ")"	!"**TYY"78%&67LF39!!'*40"2::bggll499d.K#LMM'<<6)(HNIY#&v; s4#6#677!$"5"56G''..tx7IA7M/NO''..tx7IA7M/NO&&x0&)<VH'EFF18&0A##H-02T0J##H-# ( 8. #4#6#67IF1"%6vh#?@@ 8 & Y*-Nvh+WXXYs   <GG2rC   c                    U R                   U   u  p#[        R                  " [        R                  R                  U R                  U R                  U   U5      5      n/ nU R                   H=  nUS:X  a  UR                  U5        M  UR                  U R                  U   U   5        M?     [        U5      S:  a  [        U5      OUS   nU R                  b  U R                  U5      nU R                  b  U R                  U5      nXE4$ )zv
Args:
    index (int): Index

Returns:
    tuple: (image, target) where the type of target specified by target_type.
r0   r   r   )rC   r   openr5   r6   r7   r%   r;   r'   rF   r=   rW   tupler(   r)   )rG   rC   r^   rL   imgtargetrH   s          rN   __getitem__INaturalist.__getitem__   s     

5)jjdii1D1DV1LeTU!!AF{f%d11&9!<=	 "
 #&f+/vvay>>%..%C  ,**62F{    c                 ,    [        U R                  5      $ )N)rW   rC   rG   s    rN   __len__INaturalist.__len__   s    4::rw   category_typecategory_idc                     US:X  a  U R                   U   $ XR                  ;  a  [        SU S35      eU R                  U   R                  5        H  u  p4XB:X  d  M  Us  $    [        SU SU 35      e)z
Args:
    category_type(str): one of "full", "kingdom", "phylum", "class", "order", "family", "genus" or "super"
    category_id(int): an index (class id) from this category

Returns:
    the name of the category
r0   zInvalid category type ''zInvalid category id z for )r;   r<   rc   items)rG   r|   r}   r]   ids        rN   category_nameINaturalist.category_name   s     F"&&{33$9$99 #:=/!KLL $ 5 5m D J J LHD(# !M !#7}E-!YZZrw   c                     [         R                  R                  U R                  5      =(       a,    [	        [         R
                  " U R                  5      5      S:  $ )Nr   )r5   r6   existsr%   rW   rE   ry   s    rN   r9   INaturalist._check_exists   s5    ww~~dii(KSDII1F-G!-KKrw   c                 T   U R                  5       (       a  g [        R                  R                  U R                  5      n[        [        U R                     XR                   S3[        U R                     S9  [        R                  R                  U[        R                  R                  [        U R                     5      R                  S5      5      n[        R                  R                  U5      (       d  [        SU 35      e[        R                  " X R                  5        g )Nz.tgz)filenamemd5z.tar.gzz#Unable to find downloaded files at )r9   r5   r6   dirnamer%   r   r2   r&   DATASET_MD5r7   basenamerstripr   r:   rename)rG   	base_rootorig_dir_names      rN   r*   INaturalist.download   s    GGOODII.	$&	||nD<QWbcgcocoWp	
 Y0@0@dllA[0\0c0cdm0noww~~m,,!D]OTUU
		-+rw   )r;   r<   r=   rC   r'   r&   )r   r0   NNF)r+   N)__name__
__module____qualname____firstlineno____doc__r
   strr   r   r   r   boolr4   rA   rB   rb   r	   r   ru   rz   r   r9   r*   __static_attributes____classcell__)rM   s   @rN   r#   r#       s     J $-3(,/3+6CI+6 +6 49c>*	+6
 H%+6 #8,+6 +6 
+6 +6Z00!AF sCx 8 [3 [S [S [(Lt L, ,rw   r#   )r5   os.pathpathlibr   typingr   r   r   r   r   r	   r
   PILr   utilsr   r   visionr   r@   r2   r   r#    rw   rN   <module>r      sj    	   D D D  ? !L a]][eY /..494N,- N,rw   