[docs]classFER2013(VisionDataset):"""`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. """_RESOURCES={"train":("train.csv","3f0dfb3d3fd99c811a1299cb947e3131"),"test":("test.csv","b02c2298636a634e8c2faabbf3ea9a23"),# The fer2013.csv and icml_face_data.csv files contain both train and# tests instances, and unlike test.csv they contain the labels for the# test instances. We give these 2 files precedence over train.csv and# test.csv. And yes, they both contain the same data, but with different# column names (note the spaces) and ordering:# $ head -n 1 fer2013.csv icml_face_data.csv train.csv test.csv# ==> fer2013.csv <==# emotion,pixels,Usage## ==> icml_face_data.csv <==# emotion, Usage, pixels## ==> train.csv <==# emotion,pixels## ==> test.csv <==# pixels"fer":("fer2013.csv","f8428a1edbd21e88f42c73edd2a14f95"),"icml":("icml_face_data.csv","b114b9e04e6949e5fe8b6a98b3892b1d"),}def__init__(self,root:Union[str,pathlib.Path],split:str="train",transform:Optional[Callable]=None,target_transform:Optional[Callable]=None,)->None:self._split=verify_str_arg(split,"split",("train","test"))super().__init__(root,transform=transform,target_transform=target_transform)base_folder=pathlib.Path(self.root)/"fer2013"use_fer_file=(base_folder/self._RESOURCES["fer"][0]).exists()use_icml_file=notuse_fer_fileand(base_folder/self._RESOURCES["icml"][0]).exists()file_name,md5=self._RESOURCES["fer"ifuse_fer_fileelse"icml"ifuse_icml_fileelseself._split]data_file=base_folder/file_nameifnotcheck_integrity(str(data_file),md5=md5):raiseRuntimeError(f"{file_name} not found in {base_folder} or corrupted. "f"You can download it from "f"https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge")pixels_key=" pixels"ifuse_icml_fileelse"pixels"usage_key=" Usage"ifuse_icml_fileelse"Usage"defget_img(row):returntorch.tensor([int(idx)foridxinrow[pixels_key].split()],dtype=torch.uint8).reshape(48,48)defget_label(row):ifuse_fer_fileoruse_icml_fileorself._split=="train":returnint(row["emotion"])else:returnNonewithopen(data_file,"r",newline="")asfile:rows=(rowforrowincsv.DictReader(file))ifuse_fer_fileoruse_icml_file:valid_keys=("Training",)ifself._split=="train"else("PublicTest","PrivateTest")rows=(rowforrowinrowsifrow[usage_key]invalid_keys)self._samples=[(get_img(row),get_label(row))forrowinrows]def__len__(self)->int:returnlen(self._samples)
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.