[docs]classSEMEION(VisionDataset):r"""`SEMEION <http://archive.ics.uci.edu/ml/datasets/semeion+handwritten+digit>`_ Dataset. Args: root (string): Root directory of dataset where directory ``semeion.py`` exists. transform (callable, optional): A function/transform that takes in an 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. """url="http://archive.ics.uci.edu/ml/machine-learning-databases/semeion/semeion.data"filename="semeion.data"md5_checksum="cb545d371d2ce14ec121470795a77432"def__init__(self,root:str,transform:Optional[Callable]=None,target_transform:Optional[Callable]=None,download:bool=True,)->None:super().__init__(root,transform=transform,target_transform=target_transform)ifdownload:self.download()ifnotself._check_integrity():raiseRuntimeError("Dataset not found or corrupted. You can use download=True to download it")fp=os.path.join(self.root,self.filename)data=np.loadtxt(fp)# convert value to 8 bit unsigned integer# color (white #255) the pixelsself.data=(data[:,:256]*255).astype("uint8")self.data=np.reshape(self.data,(-1,16,16))self.labels=np.nonzero(data[:,256:])[1]
[docs]def__getitem__(self,index:int)->Tuple[Any,Any]:""" Args: index (int): Index Returns: tuple: (image, target) where target is index of the target class. """img,target=self.data[index],int(self.labels[index])# doing this so that it is consistent with all other datasets# to return a PIL Imageimg=Image.fromarray(img,mode="L")ifself.transformisnotNone:img=self.transform(img)ifself.target_transformisnotNone:target=self.target_transform(target)returnimg,target
def__len__(self)->int:returnlen(self.data)def_check_integrity(self)->bool:root=self.rootfpath=os.path.join(root,self.filename)ifnotcheck_integrity(fpath,self.md5_checksum):returnFalsereturnTruedefdownload(self)->None:ifself._check_integrity():print("Files already downloaded and verified")returnroot=self.rootdownload_url(self.url,root,self.filename,self.md5_checksum)
Docs
Access comprehensive developer documentation for PyTorch
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.