
    h>(                         S SK r S SKr S SKJr  S SK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Optional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
\	\
\\\4   /\4      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.
    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.
Nrootversiontarget_type	transformtarget_transformdownloadloader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     Xpl        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)r.   super)r   DATASET_URLSkeysr#   r/   __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"   appendr(   )selfr"   r#   r$   r%   r&   r'   r(   t	dir_indexdir_namefilesfname	__class__s                X/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/inaturalist.pyr2   INaturalist.__init__F   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)sortedr3   rC   r"   r9   r>   r:   rB   splitlenr8   zipr;   rD   )	rE   krG   rH   piecescat_mapcatnamecat_ids	            rL   r?   INaturalist._init_2021v   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 layoutr/   r   r   r	   z!Unexpected non-numeric dir name:  zDuplicate category zMissing category N)r:   rS   r3   rC   r"   rB   r4   r5   r#   int
ValueErrorr8   rU   r;   extendr9   )rE   	cat_indexsuper_categoriessindexscatsubcategoriessubcatsubcat_iold_lencindexcs              rL   r@   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rA   c                 V   U R                   U   u  p#[        R                  R                  U R                  U R
                  U   U5      nU R                  b  U R                  U5      O[        R                  " U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XV4$ )zv
Args:
    index (int): Index

Returns:
    tuple: (image, target) where the type of target specified by target_type.
r.   r	   r   )rA   r3   r4   r5   r"   r9   r(   r   openr$   rD   r;   rU   tupler%   r&   )rE   rA   r\   rJ   
image_pathimgtargetrF   s           rL   __getitem__INaturalist.__getitem__   s     

5)WW\\$))T-@-@-H%P
)-)@dkk*%ejjQ[F\!!AF{f%d11&9!<=	 "
 #&f+/vvay>>%..%C  ,**62F{    c                 ,    [        U R                  5      $ )N)rU   rA   rE   s    rL   __len__INaturalist.__len__   s    4::rv   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
r.   zInvalid category type ''zInvalid category id z for )r9   r:   ra   items)rE   r{   r|   r[   ids        rL   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Zrv   c                     [         R                  R                  U R                  5      =(       a,    [	        [         R
                  " U R                  5      5      S:  $ )Nr   )r3   r4   existsr"   rU   rC   rx   s    rL   r7   INaturalist._check_exists   s5    ww~~dii(KSDII1F-G!-KKrv   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 )r7   r3   r4   dirnamer"   r
   r0   r#   DATASET_MD5r5   basenamerstripr   r8   rename)rE   	base_rootorig_dir_names      rL   r'   INaturalist.download   s    GGOODII.	$&	||nD<QWbcgcocoWp	
 Y0@0@dllA[0\0c0cdm0noww~~m,,!D]OTUU
		-+rv   )r9   r:   r;   rA   r(   r$   r#   )r   r.   NNFN)r)   N)__name__
__module____qualname____firstlineno____doc__r   strr   r=   r   r   boolr   r2   r?   r@   r`   rp   rt   ry   r   r7   r'   __static_attributes____classcell__)rK   s   @rL   r    r        s   #P $-3(,/3>B.CI. . 49c>*	.
 H%. #8,. . 5d#3"4c"9:;. 
. .`00!AF sCx : [3 [S [S [(Lt L, ,rv   r    )r3   os.pathpathlibr   typingr   r   r   r   PILr   utilsr
   r   visionr   r>   r0   r   r     rv   rL   <module>r      sg    	   1 1  ? !L a]][eY /..494U,- U,rv   