
    h                     r    d dl Z d dlZd dlmZmZmZmZ d dlZd dlm	Z	 ddl
mZmZ ddlmZ  G d de      Zy)	    N)AnyCallableOptionalUnion)Image   )check_integrityverify_str_arg)VisionDatasetc                        e Zd ZdZdddddZ	 	 	 ddeeej                  f   d	ed
e	e
   de	e
   ddf
 fdZdefdZdedeeef   fdZdefdZ xZS )FER2013af  `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                     t        |dd       _        t           |||       t	        j
                   j                        dz  }| j                  d   d   z  j                          xr# | j                  d   d   z  j                          j                  rdnrdn j                     \  }}||z  }t        t        |      |      st        | d	| d
      rdndrdndfd}	 fd}
t        |d      5 }d t        j                  |      D        }sr j                  dk(  rdndfd|D        }|D cg c]  } |	|       |
|      f c} _        d d d        y c c}w # 1 sw Y   y xY w)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                     t        j                  |    j                         D cg c]  }t        |       c}t         j                        j                  dd      S c c}w )N)dtype0   )torchtensorr   intuint8reshape)rowidx
pixels_keys     Z/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/torchvision/datasets/fer2013.pyget_imgz!FER2013.__init__.<locals>.get_imgV   sI    <<S_5J5J5L McS MUZU`U`aiijlnpqq Ms   Ac                 H    ssj                   dk(  rt        | d         S y )Nr   emotion)_splitr%   )r(   selfuse_fer_fileuse_icml_files    r+   	get_labelz#FER2013.__init__.<locals>.get_labelY   s%    }w0F3y>**     )newlinec              3       K   | ]  }|  y wN ).0r(   s     r+   	<genexpr>z#FER2013.__init__.<locals>.<genexpr>`   s     8CC8s   r   )Training)
PublicTestPrivateTestc              3   2   K   | ]  }|   v s|  y wr8   r9   )r:   r(   	usage_key
valid_keyss     r+   r;   z#FER2013.__init__.<locals>.<genexpr>d   s     Ls9~/KLs   )r
   r/   super__init__pathlibPathr   
_RESOURCESexistsr	   strRuntimeErroropencsv
DictReader_samples)r0   r   r   r   r   base_folder	file_namer   	data_filer,   r3   filerowsr(   r*   r@   r1   r2   rA   	__class__s   `             @@@@@r+   rC   zFER2013.__init__=   s    %UG5FGEUVll499-	9#dooe&<Q&??GGI((`kDOOF<STU<V.V-^-^-`,mFaealalm	3)+	s9~37+^K= 9y z  #0YX
 -H7		r	 )R( 	MD83>>$#78D}.2kkW.D]Jg
LtLGKLgclIcN;LDM	M 	M M	M 	Ms   AE?E:)E?:E??Fc                 ,    t        | j                        S r8   )lenrM   r0   s    r+   __len__zFER2013.__len__h   s    4==!!r4   r)   c                     | j                   |   \  }}t        j                  |j                               }| j                  | j	                  |      }| j
                  | j                  |      }||fS r8   )rM   r   	fromarraynumpyr   r   )r0   r)   image_tensortargetimages        r+   __getitem__zFER2013.__getitem__k   sj    #}}S1f 2 2 45>>%NN5)E  ,**62Ff}r4   c                      d| j                    S )Nzsplit=)r/   rV   s    r+   
extra_reprzFER2013.extra_reprw   s    }%%r4   )r   NN)__name__
__module____qualname____doc__rF   r   rH   rD   rE   r   r   rC   r%   rW   tupler   r^   r`   __classcell__)rS   s   @r+   r   r      s    2 C@$ CJ+J6 (,/3)MC%&)M )M H%	)M
 #8,)M 
)MV" "
s 
uS#X 
&C &r4   r   )rK   rD   typingr   r   r   r   r#   PILr   utilsr	   r
   visionr   r   r9   r4   r+   <module>rk      s+    
  1 1   2 !l&m l&r4   