Skip to content

nvtien457/NearbyPatchCL

Repository files navigation

Nearby Patch Contrastive-Learning

Overview

This repository hosts the official PyTorch implementation of NearbyPatchCL: Leveraging Nearby Patches for Self-Supervised Patch-Level Multi-Class Classification in Whole-Slide Images as presented in the International Conference on Multimedia Modeling 2024.

📝 Documentation

Installation

This source code has been developed and tested with python==3.10.12, as well as pytorch=2.1.0+cu118 and torchvision==0.16.0+cu118. We recommend using the conda package manager for installation.

  1. Clone this repo.
git clone https://github.com/nvtien457/NearbyPatchCL.git
  1. Install dependencies with conda (we provide script scripts/install.sh).
conda create -n nearby python=3.10
conda activate nearby
bash scripts/install.sh

Dataset

Dataset is cropped from Tissue Slide Images provided by CATCH dataset:

Dataset folder structure

├── data
|   ├── TRAIN_SET
|   |   ├── Histiocytoma
|   |   ├── MCT
│   │   ├── Melanoma
│   │   ├── PNST
│   │   ├── Plasmacytoma
│   │   ├── SCC
│   │   ├── Trichoblastoma
|   ├── TRAIN_SET_NEAR_0
|   ├── TRAIN_SET_NEAR_2
|   ├── ...
|   ├── TRAIN_SET_NEAR_8
|   ├── TRAIN_VAL_SET
|   |   ├── Dermis
|   |   ├── Epidermis
|   |   ├── Inflamm-Necrosis
|   |   ├── Subcutis
|   |   ├── Tumor
|   |   ├── bg
|   └── TEST_SET
  • Image name format in TRAIN_SET: [WSI_filname]_patch_[patch_id]_[x]_[y].jpg

ex: Histiocytoma_01_1_patch_000_112_60.jpg

  • Image name format in TRAIN_SET_NEAR_*: [WSI_filename]_patch_[patch_id]_[nearby_id].jpg

ex: Histiocytoma_01_1_patch_000_0.jpg

  • TRAIN_SET and TRAIN_SET_NEAR_* share similar structure (7 subfolders for tumors). TRAIN_SET contains center patches (nearby_id = 1).

  • TRAIN_VAL_SET and TEST_SET share similar structure (6 classes in skin).

1. Pre-train unsupervised

  • Use file unsup.sh.
  • Determine the path of logs, checkpoints, data folder.
  • Config setting for training is saved in .yaml file.
!python train_unsupervised.py \
    -c ./configs/SimCLR_unsup.yaml \
    --data_dir /content \
    --ckpt_dir path \
    --log_dir path
  • To train method NearbyPatchCL(N=X), use config files NEAR_X_D.yaml

2. Finetune

  • Use file finetune.sh
!python train_linear.py \
    -c ./configs/finetune.yaml \
    --data_dir Path 

3. Fully-supervised training

  • Use file sup.sh.
  • Determine the path of logs, checkpoints, data folder.
  • Config setting for training is saved in .yaml file.
!python train_supervised.py \
    -c ./configs/SimCLR_unsup.yaml \
    --data_dir /content \
    --ckpt_dir path \
    --log_dir path

4. Evaluation

  • Use file test.sh
!python test.py \
    -c ./configs/test.yaml \
    --test_dir Path

📈 Result

ℹ Citation

If our code or paper is helpful to your work, please give us star and consider citing:

@inproceedings{NearbyPatchCL,
  title        = {NearbyPatchCL: Leveraging Nearby Patches for Self-Supervised Patch-Level Multi-Class Classification in Whole-Slide Images},
  author       = {Le, Gia-Bao and Nguyen, Van-Tien and Le, Trung-Nghia and Tran, Minh-Triet},
  year         = 2024,
  book         = {MMM 2024 - The 30th International Conference on Multimedia Modeling}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages