[docs]classPCAM(VisionDataset):"""`PCAM Dataset <https://github.com/basveeling/pcam>`_. The PatchCamelyon dataset is a binary classification dataset with 327,680 color images (96px x 96px), extracted from histopathologic scans of lymph node sections. Each image is annotated with a binary label indicating presence of metastatic tissue. This dataset requires the ``h5py`` package which you can install with ``pip install h5py``. Args: root (str or ``pathlib.Path``): Root directory of the dataset. split (string, optional): The dataset split, supports ``"train"`` (default), ``"test"`` or ``"val"``. 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 into ``root/pcam``. If dataset is already downloaded, it is not downloaded again. .. warning:: To download the dataset `gdown <https://github.com/wkentaro/gdown>`_ is required. """_FILES={"train":{"images":("camelyonpatch_level_2_split_train_x.h5",# Data file name"1Ka0XfEMiwgCYPdTI-vv6eUElOBnKFKQ2",# Google Drive ID"1571f514728f59376b705fc836ff4b63",# md5 hash),"targets":("camelyonpatch_level_2_split_train_y.h5","1269yhu3pZDP8UYFQs-NYs3FPwuK-nGSG","35c2d7259d906cfc8143347bb8e05be7",),},"test":{"images":("camelyonpatch_level_2_split_test_x.h5","1qV65ZqZvWzuIVthK8eVDhIwrbnsJdbg_","d8c2d60d490dbd479f8199bdfa0cf6ec",),"targets":("camelyonpatch_level_2_split_test_y.h5","17BHrSrwWKjYsOgTMmoqrIjDy6Fa2o_gP","60a7035772fbdb7f34eb86d4420cf66a",),},"val":{"images":("camelyonpatch_level_2_split_valid_x.h5","1hgshYGWK8V-eGRy8LToWJJgDU_rXWVJ3","d5b63470df7cfa627aeec8b9dc0c066e",),"targets":("camelyonpatch_level_2_split_valid_y.h5","1bH8ZRbhSVAhScTS0p9-ZzGnX91cHT3uO","2b85f58b927af9964a4c15b8f7e8f179",),},}def__init__(self,root:Union[str,pathlib.Path],split:str="train",transform:Optional[Callable]=None,target_transform:Optional[Callable]=None,download:bool=False,):try:importh5pyself.h5py=h5pyexceptImportError:raiseRuntimeError("h5py is not found. This dataset needs to have h5py installed: please run pip install h5py")self._split=verify_str_arg(split,"split",("train","test","val"))super().__init__(root,transform=transform,target_transform=target_transform)self._base_folder=pathlib.Path(self.root)/"pcam"ifdownload:self._download()ifnotself._check_exists():raiseRuntimeError("Dataset not found. You can use download=True to download it")def__len__(self)->int:images_file=self._FILES[self._split]["images"][0]withself.h5py.File(self._base_folder/images_file)asimages_data:returnimages_data["x"].shape[0]
[docs]def__getitem__(self,idx:int)->Tuple[Any,Any]:images_file=self._FILES[self._split]["images"][0]withself.h5py.File(self._base_folder/images_file)asimages_data:image=Image.fromarray(images_data["x"][idx]).convert("RGB")targets_file=self._FILES[self._split]["targets"][0]withself.h5py.File(self._base_folder/targets_file)astargets_data:target=int(targets_data["y"][idx,0,0,0])# shape is [num_images, 1, 1, 1]ifself.transform:image=self.transform(image)ifself.target_transform:target=self.target_transform(target)returnimage,target
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.