
    QЦi                     v    S SK r S SKrS SKJrJrJrJrJr  S SKrS SK	J
r
  SSKJrJr  SSKJr   " S S\5      rg)	    N)AnyCallableOptionalTupleUnion)Image   )check_integrityverify_str_arg)VisionDatasetc                      ^  \ rS rSrSrSSSSS.r   SS	\\\R                  4   S
\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rU =r$ )FER2013   a  `FER2013
<https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge>`_ Dataset.

.. note::
    This dataset can return test labels only if ``fer2013.csv`` OR
    ``icml_face_data.csv`` are present in ``root/fer2013/``. If only
    ``train.csv`` and ``test.csv`` are present, the test labels are set to
    ``None``.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory
        ``root/fer2013`` exists. This directory may contain either
        ``fer2013.csv``, ``icml_face_data.csv``, or both ``train.csv`` and
        ``test.csv``. Precendence is given in that order, i.e. if
        ``fer2013.csv`` is present then the rest of the files will be
        ignored. All these (combinations of) files contain the same data and
        are supported for convenience, but only ``fer2013.csv`` and
        ``icml_face_data.csv`` are able to return non-None test labels.
    split (string, optional): The dataset split, supports ``"train"`` (default), or ``"test"``.
    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.
)z	train.csv 3f0dfb3d3fd99c811a1299cb947e3131)ztest.csv b02c2298636a634e8c2faabbf3ea9a23)zfer2013.csv f8428a1edbd21e88f42c73edd2a14f95)zicml_face_data.csv b114b9e04e6949e5fe8b6a98b3892b1d)traintestfericmlNrootsplit	transformtarget_transformreturnc                 r  >^ ^^^^^ [        USS5      T l        [        TT ]  XUS9  [        R
                  " T R                  5      S-  nUT R                  S   S   -  R                  5       mT(       + =(       a#    UT R                  S   S   -  R                  5       mT R                  T(       a  SOT(       a  SOT R                     u  pgXV-  n[        [        U5      US9(       d  [        U S	U S
35      eT(       a  SOSmT(       a  SOSmU4S jn	U UU4S jn
[        USSS9 nS [        R                  " U5       5       nT(       d  T(       a!  T R                  S:X  a  SOSmUU4S jU 5       nU Vs/ s H  o" U5      U
" U5      4PM     snT l        S S S 5        g s  snf ! , (       d  f       g = f)Nr   )r   r   )r   r   fer2013r   r   r   )md5z not found in z or corrupted. You can download it from https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challengez pixelspixelsz UsageUsagec                    > [         R                  " U T   R                  5        Vs/ s H  n[        U5      PM     sn[         R                  S9R                  SS5      $ s  snf )N)dtype0   )torchtensorr   intuint8reshape)rowidx
pixels_keys     [/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/fer2013.pyget_img!FER2013.__init__.<locals>.get_imgV   sO    <<S_5J5J5L M5LcS5L MUZU`U`aiijlnpqq Ms   A c                 ^   > T(       d  T(       d  TR                   S:X  a  [        U S   5      $ g )Nr   emotion)_splitr'   )r*   selfuse_fer_fileuse_icml_files    r-   	get_label#FER2013.__init__.<locals>.get_labelY   s%    }w0F3y>**    r )newlinec              3   $   #    U  H  ov   M     g 7fN ).0r*   s     r-   	<genexpr>#FER2013.__init__.<locals>.<genexpr>`   s     8#7CC#7s   r   )Training)
PublicTestPrivateTestc              3   <   >#    U  H  oT   T;   d  M  Uv   M     g 7fr=   r>   )r?   r*   	usage_key
valid_keyss     r-   r@   rA   d   s     Lt9~/Kts   	)r   r2   super__init__pathlibPathr   
_RESOURCESexistsr
   strRuntimeErroropencsv
DictReader_samples)r3   r   r   r   r   base_folder	file_namer   	data_filer.   r6   filerowsr*   r,   rF   r4   r5   rG   	__class__s   `             @@@@@r-   rI   FER2013.__init__=   s    %UG5FGEUVll499-	9#dooe&<Q&??GGI((`kDOOF<STU<V.V-^-^-`,mFaealalm	+	s9~37+^K= 9y z  #0YX
 -H7		r	 )S"-83>>$#78D}.2kkW.D]Jg
LtLGKLtgclIcN;tLDM .- M .-s   (AF(9F#F(#F((
F6c                 ,    [        U R                  5      $ r=   )lenrS   r3   s    r-   __len__FER2013.__len__h   s    4==!!r8   r+   c                     U R                   U   u  p#[        R                  " UR                  5       5      nU R                  b  U R	                  U5      nU R
                  b  U R                  U5      nXC4$ r=   )rS   r   	fromarraynumpyr   r   )r3   r+   image_tensortargetimages        r-   __getitem__FER2013.__getitem__k   sf    #}}S1 2 2 45>>%NN5)E  ,**62F}r8   c                      SU R                    3$ )Nzsplit=)r2   r]   s    r-   
extra_reprFER2013.extra_reprw   s    }%%r8   )rS   r2   )r   NN)__name__
__module____qualname____firstlineno____doc__rL   r   rN   rJ   rK   r   r   rI   r'   r^   r   r   rf   ri   __static_attributes____classcell__)rY   s   @r-   r   r      s    2 C@$ CJ+J6 (,/3)MC%&)M )M H%	)M
 #8,)M 
)M )MV" "
s 
uS#X 
&C & &r8   r   )rQ   rJ   typingr   r   r   r   r   r%   PILr   utilsr
   r   visionr   r   r>   r8   r-   <module>rv      s+    
  8 8   2 !l&m l&r8   