Datasets:

Languages:
English
ArXiv:
License:
CPathPatchFeature / README.md
nielsr's picture
nielsr HF Staff
Improve dataset card: Add task category, paper/code links, and LMDB sample usage
c374b48 verified
|
raw
history blame
6.95 kB
metadata
language:
  - en
license: apache-2.0
size_categories:
  - 100B<n<1T
tags:
  - medical
  - pathology
task_categories:
  - image-feature-extraction

CPathPatchFeature: Pre-extracted WSI Features for Computational Pathology

Paper: Revisiting End-to-End Learning with Slide-level Supervision in Computational Pathology Code: https://github.com/DearCaat/E2E-WSI-ABMILX

Dataset Summary

This dataset provides a comprehensive collection of pre-extracted features from Whole Slide Images (WSIs) for various cancer types, designed to facilitate research in computational pathology. The features are extracted using multiple state-of-the-art encoders, offering a rich resource for developing and evaluating Multiple Instance Learning (MIL) models and other deep learning architectures.

The repository contains features for the following public datasets:

  • PANDA: Prostate cANcer graDe Assessment
  • TCGA-BRCA: Breast Cancer in TCGA
  • TCGA-NSCLC: Non-Small Cell Lung Cancer in TCGA
  • TCGA-BLCA: Bladder Cancer in TCGA
  • CAMELYON: Cancer Metastases in Lymph Nodes
  • CPTAC-NSCLC: Non-Small Cell Lung Cancer in CPTAC

Dataset Structure

The features for each WSI dataset are organized into subdirectories. Each subdirectory contains the features extracted by a specific encoder, along with the corresponding patch coordinates.

Feature Encoders

The following encoders were used to generate the features:

  • UNI: A vision-language pretrained model for pathology (UNI by Chen et al.).
  • CHIEF: A feature extractor based on self-supervised learning for pathology (CHIEF by Wang et al.).
  • GIGAP: A Giga-Pixel vision model for pathology (GigaPath by Xu et al.).
  • R50: A ResNet-50 model pre-trained on ImageNet.

Some data may not be fully organized yet. If you have specific needs or questions, please feel free to open an issue in the community tab.

How to Use

You can load and access the dataset using the Hugging Face datasets library or by cloning the repository with Git LFS.

Using the datasets Library

To load the data, you can use the following Python code:

from datasets import load_dataset

# Load a specific subset (e.g., PANDA)
# Note: You may need to specify the data files manually depending on the configuration.
# Example for a hypothetical configuration named 'panda'
# ds = load_dataset("your-username/CPathPatchFeature", name="panda")

# For datasets with this structure, it's often easier to download and access files directly.
# We recommend using Git LFS for a complete download.

Note: Due to the heterogeneous structure (mixed zipped and unzipped files), direct loading with load_dataset might be complex. The recommended approach is to clone the repository.

Using Git LFS

First, ensure you have Git LFS installed and configured:

git lfs install

Then, clone the dataset repository:

git clone https://huggingface.co/datasets/Dearcat/CPathPatchFeature

Sample Usage

Here is an example of loading data from an LMDB dataset, as provided in the GitHub repository:

import lmdb
import torch
import pickle
from datasets.utils import imfrombytes # Ensure this utility function is correctly referenced

slide_name = "xxxx"  # Example slide name
path_to_lmdb = "YOUR_PATH_TO_LMDB_FILE" # e.g., "/path/to/my_dataset_256_level0.lmdb"

# Open LMDB dataset
env = lmdb.open(path_to_lmdb, subdir=False, readonly=True, lock=False,
                readahead=False, meminit=False, map_size=100 * (1024**3))

with env.begin(write=False) as txn:
    # Get patch count for the slide
    pn_dict = pickle.loads(txn.get(b'__pn__'))
    if slide_name not in pn_dict:
        raise ValueError(f"Slide ID {slide_name} not found in LMDB metadata.")
    num_patches = pn_dict[slide_name]

    # Generate patch IDs
    patch_ids = [f"{slide_name}-{i}" for i in range(num_patches)]

    # Allocate memory for patches (adjust dimensions and dtype as needed)
    # Assuming patches are 224x224, 3 channels, and will be normalized later
    patches_tensor = torch.empty((len(patch_ids), 3, 224, 224), dtype=torch.float32)

    # Load and decode data into torch.tensor
    for i, key_str in enumerate(patch_ids):
        patch_bytes = txn.get(key_str.encode('ascii'))
        if patch_bytes is None:
            print(f"Warning: Key {key_str} not found in LMDB.")
            continue
        # Assuming the stored value is pickled image bytes
        img_array = imfrombytes(pickle.loads(patch_bytes).tobytes()) # Or .tobytes() if it's already bytes
        patches_tensor[i] = torch.from_numpy(img_array.transpose(2, 0, 1)) # HWC to CHW

# Normalize the data (example using ImageNet stats)
# Ensure values are in [0, 255] before this normalization if they aren't already
mean = torch.tensor([0.485, 0.456, 0.406]).view((1, 3, 1, 1)) * 255.0
std = torch.tensor([0.229, 0.224, 0.225]).view((1, 3, 1, 1)) * 255.0

# If your patches_tensor is already in [0,1] range, remove * 255.0 from mean/std
# If your patches_tensor is uint8 [0,255], convert to float first: patches_tensor.float()
patches_tensor = (patches_tensor.float() - mean) / std

env.close()

Citation

This dataset has been used in the following publications. If you find it useful for your research, please consider citing them:

@misc{tang2025revisitingdatachallengescomputational,
      title={Revisiting Data Challenges of Computational Pathology: A Pack-based Multiple Instance Learning Framework}, 
      author={Wenhao Tang and Heng Fang and Ge Wu and Xiang Li and Ming-Ming Cheng},
      year={2025},
      eprint={2509.20923},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={[https://arxiv.org/abs/2509.20923](https://arxiv.org/abs/2509.20923)}, 
}

@misc{tang2025multipleinstancelearningframework,
      title={Multiple Instance Learning Framework with Masked Hard Instance Mining for Gigapixel Histopathology Image Analysis}, 
      author={Wenhao Tang and Sheng Huang and Heng Fang and Fengtao Zhou and Bo Liu and Qingshan Liu},
      year={2025},
      eprint={2509.11526},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={[https://arxiv.org/abs/2509.11526](https://arxiv.org/abs/2509.11526)}, 
}

@misc{tang2025revisitingendtoendlearningslidelevel,
      title={Revisiting End-to-End Learning with Slide-level Supervision in Computational Pathology}, 
      author={Wenhao Tang and Rong Qin and Heng Fang and Fengtao Zhou and Hao Chen and Xiang Li and Ming-Ming Cheng},
      year={2025},
      eprint={2506.02408},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={[https://arxiv.org/abs/2506.02408](https://arxiv.org/abs/2506.02408)}, 
}