a
    h9                     @   sh   d dl mZ d dlmZmZmZmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ G dd deZd	S )
    )Path)AnyCallableOptionalUnion   )default_loader)check_integritydownload_and_extract_archivedownload_urlverify_str_arg)VisionDatasetc                
       s   e Zd ZdZdZddddZddd	d
Zddddefee	e
f e	ee ee eeee	e
f gef dd fddZedddZeeeef dddZe	dddZdd Zdd Zg dZ  ZS )
Flowers102aC  `Oxford 102 Flower <https://www.robots.ox.ac.uk/~vgg/data/flowers/102/>`_ Dataset.

    .. warning::

        This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.

    Oxford 102 Flower is an image classification dataset consisting of 102 flower categories. The
    flowers were chosen to be flowers commonly occurring in the United Kingdom. Each class consists of
    between 40 and 258 images.

    The images have large scale, pose and light variations. In addition, there are categories that
    have large variations within the category, and several very similar categories.

    Args:
        root (str or ``pathlib.Path``): Root directory of the dataset.
        split (string, optional): The dataset split, supports ``"train"`` (default), ``"val"``, or ``"test"``.
        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.
    z2https://www.robots.ox.ac.uk/~vgg/data/flowers/102/)z102flowers.tgzZ 52808999861908f626f3c1f4e79d11fa)zimagelabels.matZ e0620be6f572b9609742df49c70aed4d)z	setid.matZ a5357ecc9cb78c4bef273ce3793fc85c)imagelabelsetidZtrnidZvalidZtstidtrainvaltestr   NF)rootsplit	transformtarget_transformdownloadloaderreturnc                    s  t  j|||d t|dd| _t| jd | _| jd | _|rH|   | 	 sXt
dddlm} || j| jd	 d  d
d}|| j| j   }	|| j| jd d  d
d}
tt|
d d  d}g | _g | _|	D ]0}| j||  | j| jd|dd  q|| _d S )N)r   r   r   r   zflowers-102ZjpgzHDataset not found or corrupted. You can use download=True to download itr   )loadmatr   T)Z
squeeze_mer   labelsr   Zimage_Z05dz.jpg)super__init__r   _splitr   r   _base_folder_images_folderr   _check_integrityRuntimeErrorZscipy.ior   
_file_dict_splits_maptolistdict	enumerate_labels_image_filesappendr   )selfr   r   r   r   r   r   r   Zset_idsZ	image_idsr   Zimage_id_to_labelZimage_id	__class__ M/var/www/auris/lib/python3.9/site-packages/torchvision/datasets/flowers102.pyr    .   s&    	zFlowers102.__init__)r   c                 C   s
   t | jS N)lenr,   r.   r1   r1   r2   __len__R   s    zFlowers102.__len__)idxr   c                 C   sH   | j | | j|  }}| |}| jr0| |}| jr@| |}||fS r3   )r,   r+   r   r   r   )r.   r7   Z
image_filer   r   r1   r1   r2   __getitem__U   s    


zFlowers102.__getitem__c                 C   s   d| j  S )Nzsplit=)r!   r5   r1   r1   r2   
extra_repra   s    zFlowers102.extra_reprc                 C   sN   | j  r| j  sdS dD ],}| j| \}}tt| j| |s dS qdS )NFr   r   T)r#   existsis_dirr&   r	   strr"   r.   idfilenamemd5r1   r1   r2   r$   d   s    zFlowers102._check_integrityc                 C   st   |   rd S t| j | jd d  t| j| jd d d dD ],}| j| \}}t| j| t| j|d qBd S )Nr   r   r   )rA   r:   )r$   r
   _download_url_prefixr&   r=   r"   r   r>   r1   r1   r2   r   n   s    zFlowers102.download)fzpink primrosezhard-leaved pocket orchidzcanterbury bellsz	sweet peazenglish marigoldz
tiger lilyzmoon orchidzbird of paradiseZ	monkshoodzglobe thistleZ
snapdragonzcolt's footzking proteazspear thistlezyellow iriszglobe-flowerzpurple coneflowerzperuvian lilyzballoon flowerzgiant white arum lilyz	fire lilyzpincushion flowerZ
fritillaryz
red gingerzgrape hyacinthz
corn poppyzprince of wales featherszstemless gentianZ	artichokezsweet williamZ	carnationzgarden phloxzlove in the mistzmexican asterzalpine sea hollyzruby-lipped cattleyazcape flowerzgreat masterwortz
siam tulipzlenten rosezbarbeton daisyZdaffodilz
sword lilyZ
poinsettiazbolero deep blueZ
wallflowerZmarigoldZ	buttercupzoxeye daisyzcommon dandelionZpetuniaz
wild pansyZprimulaZ	sunflowerZpelargoniumzbishop of llandaffZgauraZgeraniumzorange dahliazpink-yellow dahlia?zcautleya spicatazjapanese anemonezblack-eyed susanZ
silverbushzcalifornian poppyZosteospermumzspring crocuszbearded irisZ
windflowerz
tree poppyZgazaniaZazaleaz
water lilyZrosezthorn applezmorning gloryzpassion flowerZlotusz	toad lilyZ	anthuriumZ
frangipaniZclematisZhibiscusZ	columbinezdesert-roseztree mallowZmagnoliaZcyclamenZ
watercressz
canna lilyZhippeastrumzbee balmz	ball mossZfoxgloveZbougainvilleaZcamelliaZmallowzmexican petuniaZbromeliazblanket flowerztrumpet creeperzblackberry lily)__name__
__module____qualname____doc__rB   r&   r'   r   r   r=   r   r   r   boolr   r    intr6   tupler8   r9   r$   r   classes__classcell__r1   r1   r/   r2   r   
   s6   
$
r   N)pathlibr   typingr   r   r   r   folderr   utilsr	   r
   r   r   Zvisionr   r   r1   r1   r1   r2   <module>   s
   