o
    ôj¥  ã                   @   sd   d dl 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mZ ddlmZ G dd„ deƒZdS )	é    N)ÚAnyÚCallableÚOptionalÚTupleÚUnion)ÚImageé   )Ú_decompressÚdownload_file_from_google_driveÚverify_str_arg)ÚVisionDatasetc                       s°   e Zd ZdZdddœdddœdddœd	œZ	
			ddeeejf dede	e
 de	e
 def
‡ fdd„Zdefdd„Zdedeeef fdd„Zdefdd„Zddd„Z‡  ZS ) ÚPCAMaÀ  `PCAM Dataset   <https://github.com/basveeling/pcam>`_.

    The PatchCamelyon dataset is a binary classification dataset with 327,680
    color images (96px x 96px), extracted from histopathologic scans of lymph node
    sections. Each image is annotated with a binary label indicating presence of
    metastatic tissue.

    This dataset requires the ``h5py`` package which you can install with ``pip install h5py``.

    Args:
         root (str or ``pathlib.Path``): Root directory of the dataset.
         split (string, optional): The dataset split, supports ``"train"`` (default), ``"test"`` or ``"val"``.
         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 into ``root/pcam``. If
             dataset is already downloaded, it is not downloaded again.

             .. warning::

                To download the dataset `gdown <https://github.com/wkentaro/gdown>`_ is required.
    )z&camelyonpatch_level_2_split_train_x.h5z!1Ka0XfEMiwgCYPdTI-vv6eUElOBnKFKQ2Z 1571f514728f59376b705fc836ff4b63)z&camelyonpatch_level_2_split_train_y.h5z!1269yhu3pZDP8UYFQs-NYs3FPwuK-nGSGZ 35c2d7259d906cfc8143347bb8e05be7)ÚimagesÚtargets)z%camelyonpatch_level_2_split_test_x.h5Z!1qV65ZqZvWzuIVthK8eVDhIwrbnsJdbg_Z d8c2d60d490dbd479f8199bdfa0cf6ec)z%camelyonpatch_level_2_split_test_y.h5Z!17BHrSrwWKjYsOgTMmoqrIjDy6Fa2o_gPZ 60a7035772fbdb7f34eb86d4420cf66a)z&camelyonpatch_level_2_split_valid_x.h5z!1hgshYGWK8V-eGRy8LToWJJgDU_rXWVJ3Z d5b63470df7cfa627aeec8b9dc0c066e)z&camelyonpatch_level_2_split_valid_y.h5z!1bH8ZRbhSVAhScTS0p9-ZzGnX91cHT3uOZ 2b85f58b927af9964a4c15b8f7e8f179©ÚtrainÚtestÚvalr   NFÚrootÚsplitÚ	transformÚtarget_transformÚdownloadc                    s|   z	dd l }|| _ W n ty   tdƒ‚w t|ddƒ| _tƒ j|||d� t | j	¡d | _
|r4|  ¡  |  ¡ s<tdƒ‚d S )Nr   zYh5py is not found. This dataset needs to have h5py installed: please run pip install h5pyr   r   )r   r   Úpcamz;Dataset not found. You can use download=True to download it)Úh5pyÚImportErrorÚRuntimeErrorr   Ú_splitÚsuperÚ__init__ÚpathlibÚPathr   Ú_base_folderÚ	_downloadÚ_check_exists)Úselfr   r   r   r   r   r   ©Ú	__class__© új/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/pcam.pyr   I   s    
ÿÿÿzPCAM.__init__Úreturnc                 C   sX   | j | j d d }| j | j| ¡�}|d jd W  d   ƒ S 1 s%w   Y  d S )Nr   r   Úx)Ú_FILESr   r   ÚFiler"   Úshape)r%   Úimages_fileÚimages_datar(   r(   r)   Ú__len__e   s   $ÿzPCAM.__len__Úidxc                 C   sä   | j | j d d }| j | j| ¡�}t |d | ¡ d¡}W d   ƒ n1 s*w   Y  | j | j d d }| j | j| ¡�}t|d |dddf ƒ}W d   ƒ n1 sYw   Y  | j	rf|  	|¡}| j
rn|  
|¡}||fS )Nr   r   r+   ÚRGBr   Úy)r,   r   r   r-   r"   r   Ú	fromarrayÚconvertÚintr   r   )r%   r2   r/   r0   ÚimageÚtargets_fileZtargets_dataÚtargetr(   r(   r)   Ú__getitem__j   s   ÿÿ

zPCAM.__getitem__c                    sB   ˆ j ˆ j d d }ˆ j ˆ j d d }t‡ fdd„||fD ƒƒS )Nr   r   r   c                 3   s    � | ]}ˆ j  |¡ ¡ V  qd S )N)r"   ÚjoinpathÚexists)Ú.0Zh5_file©r%   r(   r)   Ú	<genexpr>}   s   € z%PCAM._check_exists.<locals>.<genexpr>)r,   r   Úall)r%   r/   r9   r(   r?   r)   r$   z   s   zPCAM._check_existsc                 C   s\   |   ¡ rd S | j| j  ¡ D ]\}}}|d }t|t| jƒ||d� tt| j| ƒƒ qd S )Nz.gz)ÚfilenameÚmd5)r$   r,   r   Úvaluesr
   Ústrr"   r	   )r%   Ú	file_nameÚfile_idrC   Úarchive_namer(   r(   r)   r#      s   ýzPCAM._download)r   NNF)r*   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r   rE   r    r!   r   r   Úboolr   r7   r1   r   r   r;   r$   r#   Ú__classcell__r(   r(   r&   r)   r   
   s>    úúúç*úþýüûúr   )r    Útypingr   r   r   r   r   ÚPILr   Úutilsr	   r
   r   Úvisionr   r   r(   r(   r(   r)   Ú<module>   s    