
    ڧg}                         d dl Zd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlZd dlmZ ddlmZmZmZ ddlmZ  G d d	e          ZdS )
    N)Path)AnyCallablecastOptionalTupleUnion)Image   )check_integritydownload_and_extract_archiveverify_str_arg)VisionDatasetc                       e Zd ZdZdZdZdZdZdZdZ	dd	gd
dgddggZ
ddgddggZdZ	 	 	 	 	 d)deeef         dedee         dee         dee         deddf fdZdee         dee         fdZdedeeef         fd Zdefd!Zd*d"ed#ee         deej        eej                 f         fd$Zdefd%Zd+d&Zdefd'Zdee         ddfd(Z  xZ!S ),STL10a  `STL10 <https://cs.stanford.edu/~acoates/stl10/>`_ Dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of dataset where directory
            ``stl10_binary`` exists.
        split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.
            Accordingly, dataset is selected.
        folds (int, optional): One of {0-9} or None.
            For training, loads one of the 10 pre-defined folds of 1k samples for the
            standard evaluation procedure. If no value is passed, loads the 5k samples.
        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.
    stl10_binaryz9http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gzzstl10_binary.tar.gz 91f7769df0f17e558f3565bffb0c7dfbzclass_names.txtzfold_indices.txtztrain_X.bin 918c2871b30a85fa023e0c44e0bee87fztrain_y.bin 5a34089d4802c674881badbb80307741zunlabeled_X.bin 5242ba1fed5e4be9e1e742405eb56ca4z
test_X.bin 7f263ba9f9e0b06b93213547f721ac82z
test_y.bin 36f9794fa4beb8a2c72628de14fa638e)traintrain+unlabeled	unlabeledtestr   NFrootsplitfolds	transformtarget_transformdownloadreturnc                    t                                          |||           t          |d| j                  | _        |                     |          | _        |r|                                  n#|                                 st          d          |  | j        dk    r| 
                    | j        d         d         | j        d         d                   \  | _        | _        t          t          j        | j                  | _        |                     |           n| j        dk    r	| 
                    | j        d         d         | j        d         d                   \  | _        | _        t          t          j        | j                  | _        |                     |           | 
                    | j        d         d                   \  }}t          j        | j        |f          | _        t          j        | j        t          j        d	g|j        d         z            f          | _        n| j        d
k    r\| 
                    | j        d         d                   \  | _        }t          j        d	g| j        j        d         z            | _        nE| 
                    | j        d         d         | j        d         d                   \  | _        | _        t,          j                            | j        | j        | j                  }	t,          j                            |	          rUt;          |	          5 }
|
                                                                | _         d d d            d S # 1 swxY w Y   d S d S )N)r    r!   r   zHDataset not found or corrupted. You can use download=True to download itr   r   r   r      r   )!super__init__r   splitsr   _verify_foldsr   r"   _check_integrityRuntimeError_STL10__loadfile
train_listdatalabelsr   npndarray_STL10__load_foldsconcatenateasarrayshape	test_listospathjoinr   base_folderclass_names_fileisfileopenread
splitlinesclasses)selfr   r   r   r    r!   r"   unlabeled_data_
class_filef	__class__s              V/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/stl10.pyr(   zSTL10.__init__/   s/    	EUVVV#E7DK@@
''..
 	kMMOOOO&&(( 	kijjj 	):  %)__T_Q5G5JDO\]L^_`La%b%b"DIt{rz4;77DKe$$$$Z,,,%)__T_Q5G5JDO\]L^_`La%b%b"DIt{rz4;77DKe$$$ $0B10E F FNA	>'BCCDI.$+rz2$I]^_I`B`7a7a)bccDKKZ;&&??4?1+=a+@AALDIq*bTDIOA,>%>??DKK%)__T^A5Fq5I4>Z[K\]^K_%`%`"DIt{W\\$)T-=t?TUU
7>>*%% 	5j!! 5Q vvxx22445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5s   ,M::M>M>c                    ||S t          |t                    r7|t          d          v r|S d}t          |                    |                    d}t          |                    t          |                              )N
   zDValue for argument folds should be in the range [0, 10), but got {}.z>Expected type None or int for argument folds, but got type {}.)
isinstanceintrange
ValueErrorformattype)rB   r   msgs      rH   r*   zSTL10._verify_folds[   sx    =Ls## 	6b		!!XCSZZ..///RCSZZU44555    indexc                 D   | j         (| j        |         t          | j         |                   }}n| j        |         d}}t          j        t          j        |d                    }| j        |                     |          }| j        |                     |          }||fS )z
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        N)r   r%   r   )	r0   r/   rL   r
   	fromarrayr1   	transposer    r!   )rB   rS   imgtargets       rH   __getitem__zSTL10.__getitem__g   s     ;")E*CE0B,C,CCC)E*DC obl3	::;;>%..%%C ,**622FF{rR   c                 &    | j         j        d         S )Nr   )r/   r6   rB   s    rH   __len__zSTL10.__len__   s    yq!!rR   	data_filelabels_filec                 8   d }|rvt           j                            | j        | j        |          }t          |d          5 }t          j        |t          j                  dz
  }d d d            n# 1 swxY w Y   t           j                            | j        | j        |          }t          |d          5 }t          j        |t          j                  }t          j	        |d          }t          j
        |d          }d d d            n# 1 swxY w Y   ||fS )Nrb)dtyper   )r&      `   rc   )r   r   rb   r%   )r8   r9   r:   r   r;   r>   r1   fromfileuint8reshaperV   )	rB   r]   r^   r0   path_to_labelsrF   path_to_data
everythingimagess	            rH   
__loadfilezSTL10.__loadfile   sl    	<W\\$)T5E{SSNnd++ <qQbh777!;< < < < < < < < < < < < < < < w||DIt/?KK,%% 	8Qbh777JZ
O<<F\&,77F		8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 v~s%    $A00A47A46ADDDc                     | j         | j        z   D ]C\  }}t          j                            | j        | j        |          }t          ||          s dS DdS )NFT)r.   r7   r8   r9   r:   r   r;   r   )rB   filenamemd5fpaths       rH   r+   zSTL10._check_integrity   s]    !_t~= 	 	MHcGLLD,<hGGE"5#.. uutrR   c                     |                                  rt          d           d S t          | j        | j        | j        | j                   |                                   d S )Nz%Files already downloaded and verified)rm   rn   )r+   printr   urlr   rm   tgz_md5r[   s    rH   r"   zSTL10.download   sc      "" 	9:::F$TXty4=VZVbccccrR   c                 &     dj         di | j        S )NzSplit: {split} )rO   __dict__r[   s    rH   
extra_reprzSTL10.extra_repr   s    &&77777rR   c                    |d S t           j                            | j        | j        | j                  }t          |          5 }|                                                                |         }t          j
        |t          j        d          }| j        |d d d d d d f         | _        | j        | j        |         | _        d d d            d S # 1 swxY w Y   d S )N )ra   sep)r8   r9   r:   r   r;   folds_list_filer>   r?   r@   r1   
fromstringint64r/   r0   )rB   r   path_to_foldsrF   str_idxlist_idxs         rH   __load_foldszSTL10.__load_folds   s	   =FTY0@$BVWW-   	4Affhh))++E2G}WBH#FFFH	(AAAqqq!!!"34DI{&"k(3	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   BCCC)r   NNNF)N)r#   N)"__name__
__module____qualname____doc__r;   rr   rm   rs   r<   r{   r.   r7   r)   r	   strr   r   rL   r   boolr(   r*   r   r   rY   r\   r1   r2   r-   r+   r"   rw   r3   __classcell__)rG   s   @rH   r   r      sB        & !K
EC$H0G((O	:;	:;	>?J  BClTvEwxI>F
 #(,/3*5 *5CI*5 *5 }	*5
 H%*5 #8,*5 *5 
*5 *5 *5 *5 *5 *5X
68C= 
6Xc] 
6 
6 
6 
6 sCx    4" " " " " C hsm uUWU_aijljtauUuOv     $           8C 8 8 8 8
4(3- 
4D 
4 
4 
4 
4 
4 
4 
4 
4rR   r   )os.pathr8   pathlibr   typingr   r   r   r   r   r	   numpyr1   PILr
   utilsr   r   r   visionr   r   ru   rR   rH   <module>r      s           > > > > > > > > > > > > > > > >           P P P P P P P P P P ! ! ! ! ! !c4 c4 c4 c4 c4M c4 c4 c4 c4 c4rR   