
    QЦi                     j    S SK r S SKJrJrJrJrJr  S SKJr  SSK	J
r
JrJr  SSKJr   " S S\5      rg)	    N)AnyCallableOptionalTupleUnion)Image   )_decompressdownload_file_from_google_driveverify_str_arg)VisionDatasetc                      ^  \ rS rSrSrSSS.SSS.SS	S.S
.r    SS\\\R                  4   S\S\
\   S\
\   S\4
U 4S jjjrS\4S jrS\S\\\4   4S jrS\4S jrSS jrSrU =r$ )PCAM
   a  `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-vv6eUElOBnKFKQ2 1571f514728f59376b705fc836ff4b63)z&camelyonpatch_level_2_split_train_y.h5z!1269yhu3pZDP8UYFQs-NYs3FPwuK-nGSG 35c2d7259d906cfc8143347bb8e05be7)imagestargets)z%camelyonpatch_level_2_split_test_x.h5!1qV65ZqZvWzuIVthK8eVDhIwrbnsJdbg_ d8c2d60d490dbd479f8199bdfa0cf6ec)z%camelyonpatch_level_2_split_test_y.h5!17BHrSrwWKjYsOgTMmoqrIjDy6Fa2o_gP 60a7035772fbdb7f34eb86d4420cf66a)z&camelyonpatch_level_2_split_valid_x.h5z!1hgshYGWK8V-eGRy8LToWJJgDU_rXWVJ3 d5b63470df7cfa627aeec8b9dc0c066e)z&camelyonpatch_level_2_split_valid_y.h5z!1bH8ZRbhSVAhScTS0p9-ZzGnX91cHT3uO 2b85f58b927af9964a4c15b8f7e8f179traintestvalrootsplit	transformtarget_transformdownloadc                 L  >  SS K nX`l         [        USS5      U l        [
        TU ]  XUS9  [        R                  " U R                  5      S-  U l
        U(       a  U R                  5         U R                  5       (       d  [        S5      eg ! [         a    [        S5      ef = f)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__s          X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/pcam.pyr+   PCAM.__init__I   s    	I %UG5MNEUV#LL3f<NN!!##\]] $  	k 	s   
B B#returnc                     U R                   U R                     S   S   nU R                  R                  U R                  U-  5       nUS   R
                  S   sS S S 5        $ ! , (       d  f       g = f)Nr   r   x)_FILESr)   r&   Filer.   shape)r1   images_fileimages_datas      r3   __len__PCAM.__len__e   sZ    kk$++.x8;YY^^D--;<s#))!, =<<s   A$$
A2idxc                    U R                   U R                     S   S   nU R                  R                  U R                  U-  5       n[
        R                  " US   U   5      R                  S5      nS S S 5        U R                   U R                     S   S   nU R                  R                  U R                  U-  5       n[        US   USSS4   5      nS S S 5        U R                  (       a  U R                  W5      nU R                  (       a  U R                  W5      nWW4$ ! , (       d  f       N= f! , (       d  f       Ng= f)Nr   r   r7   RGBr   y)r8   r)   r&   r9   r.   r   	fromarrayconvertintr!   r"   )r1   r?   r;   r<   imagetargets_filetargets_datatargets           r3   __getitem__PCAM.__getitem__j   s   kk$++.x8;YY^^D--;<OOK$4S$9:BB5IE = {{4;;/	:1=YY^^D--<=c*31a<89F > >>NN5)E  **62Ff} =< >=s   ,D)D:)
D7:
Ec                    ^  T R                   T R                     S   S   nT R                   T R                     S   S   n[        U 4S jX4 5       5      $ )Nr   r   r   c              3   v   >#    U  H.  nTR                   R                  U5      R                  5       v   M0     g 7f)N)r.   joinpathexists).0h5_filer1   s     r3   	<genexpr>%PCAM._check_exists.<locals>.<genexpr>}   s0     kOjG4$$--g6==??Ojs   69)r8   r)   all)r1   r;   rG   s   `  r3   r0   PCAM._check_existsz   sP    kk$++.x8;{{4;;/	:1=kP[Ojkkk    c                    U R                  5       (       a  g U R                  U R                     R                  5        HJ  u  pnUS-   n[	        U[        U R                  5      XCS9  [        [        U R                  U-  5      5        ML     g )Nz.gz)filenamemd5)r0   r8   r)   valuesr   strr.   r
   )r1   	file_namefile_idrY   archive_names        r3   r/   PCAM._download   st    '+{{4;;'?'F'F'H#I$u,L+GS9J9J5KVblD--<=> (IrV   )r.   r)   r&   )r   NNF)r5   N)__name__
__module____qualname____firstlineno____doc__r8   r   r[   r,   r-   r   r   boolr+   rE   r=   r   r   rJ   r0   r/   __static_attributes____classcell__)r2   s   @r3   r   r   
   s    2





3%FT (,/3^C%&^ ^ H%	^
 #8,^ ^ ^8- -
s uS#X  lt l
? ?rV   r   )r,   typingr   r   r   r   r   PILr   utilsr
   r   r   visionr   r    rV   r3   <module>rm      s(     8 8  O O !|?= |?rV   