LG-AI-EXAONE/EXAONEPath

Python

23

0 commits

updated Jan 8, 2025

See the code

README

EXAONEPath

EXAONEPath 1.0 Patch-level Foundation Model for Pathology

[Paper] [Hugging Face] [Model] [BibTeX]

Introduction

We introduce EXAONEPath, a patch-level pathology pretrained model with 86 million parameters. The model was pretrained on 285,153,903 patches extracted from a total of 34,795 WSIs. EXAONEPath demonstrates superior performance considering the number of WSIs used and the model's parameter count.

Quickstart

Load EXAONEPath and run inference on tile-level images.

1. Hardware Requirements

  • NVIDIA GPU is required
  • Minimum 8GB GPU memory recommended
  • NVIDIA driver version >= 450.80.02 required

Note: This implementation requires NVIDIA GPU and drivers. The provided environment setup specifically uses CUDA-enabled PyTorch, making NVIDIA GPU mandatory for running the model.

2. Environment Setup

First, install Conda if you haven't already. You can find installation instructions here. Then create and activate the environment using the provided configuration:

git clone https://github.com/LG-AI-EXAONE/EXAONEPath.git
cd EXAONEPath
conda env create -f environment.yaml
conda activate exaonepath

3. Load the model & Inference

Load with HuggingFace

import torch
from PIL import Image
from macenko import macenko_normalizer
import torchvision.transforms as transforms
from vision_transformer import VisionTransformer

hf_token = "YOUR_HUGGING_FACE_ACCESS_TOKEN"
model = VisionTransformer.from_pretrained("LGAI-EXAONE/EXAONEPath", use_auth_token=hf_token)

transform = transforms.Compose(
    [
        transforms.Resize(256, interpolation=transforms.InterpolationMode.BICUBIC),
        transforms.CenterCrop(224),
        transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ]
)

normalizer = macenko_normalizer()
img_path = "images/MHIST_aaa.png"
image = Image.open(img_path).convert("RGB")
image_macenko = normalizer(image)

sample_input = transform(image_macenko).unsqueeze(0)
model.cuda()
model.eval()

features = model(sample_input.cuda())

Load Manually

First, download the EXAONEPath model checkpoint from here

import torch
from PIL import Image
from macenko import macenko_normalizer
import torchvision.transforms as transforms
from vision_transformer import vit_base

file_path = "MODEL_CHECKPOINT_PATH"
checkpoint = torch.load(file_path, map_location=torch.device('cpu'))
state_dict = checkpoint['state_dict']
model = vit_base(patch_size=16, num_classes=0)
msg = model.load_state_dict(state_dict, strict=False)
print(f'Pretrained weights found at {file_path} and loaded with msg: {msg}')

transform = transforms.Compose(
    [
        transforms.Resize(256, interpolation=transforms.InterpolationMode.BICUBIC),
        transforms.CenterCrop(224),
        transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ]
)

normalizer = macenko_normalizer()
img_path = "images/MHIST_aaa.png"
image = Image.open(img_path).convert("RGB")
image_macenko = normalizer(image)

sample_input = transform(image_macenko).unsqueeze(0)
model.cuda()
model.eval()

features = model(sample_input.cuda())

Model Performance Comparison

We report linear evaluation result on six downstream tasks. Top-1 accuracy is shown, with values for models other than Gigapath taken from the RudolfV paper.

ModelPCAMMHISTCRC-100KTIL Det.MSI CRCMSI STADAvg
ResNet50 ImageNet0.8330.8060.8490.9150.6530.6640.787
ViT-L/16 ImageNet0.8520.7960.8470.9240.6690.6710.793
Lunit0.9180.7710.9490.9430.7450.7560.847
CTransPath0.8720.8170.8400.9300.6940.7260.813
Phikon0.9060.7950.8830.9460.7330.7510.836
Virchow0.9330.8340.968----
RudolfV0.9440.8210.9730.9430.7550.7880.871
GigaPath (patch encoder)0.9470.8220.9640.9380.7530.7480.862
EXAONEPath (ours)0.9010.8180.9460.9390.7560.8040.861

Model Comparison Param Model Comparison WSIS
Figure 1. Performance comparison of models based on the number of parameters and the number of WSIs used for training. The average Top-1 accuracy represents the mean linear evaluation performance across six downstream tasks.

License

The model is licensed under EXAONEPath AI Model License Agreement 1.0 - NC

Citation

If you find EXAONEPath useful, please cite it using this BibTeX:

@article{yun2024exaonepath,
  title={EXAONEPath 1.0 Patch-level Foundation Model for Pathology},
  author={Yun, Juseung and Hu, Yi and Kim, Jinhyung and Jang, Jongseong and Lee, Soonyoung},
  journal={arXiv preprint arXiv:2408.00380},
  year={2024}
}

Contact

LG AI Research Technical Support: [email protected]

LG-AI-EXAONE/EXAONEPath

Python

23

0 commits

updated Jan 8, 2025

See the code

README

EXAONEPath

EXAONEPath 1.0 Patch-level Foundation Model for Pathology

[Paper] [Hugging Face] [Model] [BibTeX]

Introduction

We introduce EXAONEPath, a patch-level pathology pretrained model with 86 million parameters. The model was pretrained on 285,153,903 patches extracted from a total of 34,795 WSIs. EXAONEPath demonstrates superior performance considering the number of WSIs used and the model's parameter count.

Quickstart

Load EXAONEPath and run inference on tile-level images.

1. Hardware Requirements

  • NVIDIA GPU is required
  • Minimum 8GB GPU memory recommended
  • NVIDIA driver version >= 450.80.02 required

Note: This implementation requires NVIDIA GPU and drivers. The provided environment setup specifically uses CUDA-enabled PyTorch, making NVIDIA GPU mandatory for running the model.

2. Environment Setup

First, install Conda if you haven't already. You can find installation instructions here. Then create and activate the environment using the provided configuration:

git clone https://github.com/LG-AI-EXAONE/EXAONEPath.git
cd EXAONEPath
conda env create -f environment.yaml
conda activate exaonepath

3. Load the model & Inference

Load with HuggingFace

import torch
from PIL import Image
from macenko import macenko_normalizer
import torchvision.transforms as transforms
from vision_transformer import VisionTransformer

hf_token = "YOUR_HUGGING_FACE_ACCESS_TOKEN"
model = VisionTransformer.from_pretrained("LGAI-EXAONE/EXAONEPath", use_auth_token=hf_token)

transform = transforms.Compose(
    [
        transforms.Resize(256, interpolation=transforms.InterpolationMode.BICUBIC),
        transforms.CenterCrop(224),
        transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ]
)

normalizer = macenko_normalizer()
img_path = "images/MHIST_aaa.png"
image = Image.open(img_path).convert("RGB")
image_macenko = normalizer(image)

sample_input = transform(image_macenko).unsqueeze(0)
model.cuda()
model.eval()

features = model(sample_input.cuda())

Load Manually

First, download the EXAONEPath model checkpoint from here

import torch
from PIL import Image
from macenko import macenko_normalizer
import torchvision.transforms as transforms
from vision_transformer import vit_base

file_path = "MODEL_CHECKPOINT_PATH"
checkpoint = torch.load(file_path, map_location=torch.device('cpu'))
state_dict = checkpoint['state_dict']
model = vit_base(patch_size=16, num_classes=0)
msg = model.load_state_dict(state_dict, strict=False)
print(f'Pretrained weights found at {file_path} and loaded with msg: {msg}')

transform = transforms.Compose(
    [
        transforms.Resize(256, interpolation=transforms.InterpolationMode.BICUBIC),
        transforms.CenterCrop(224),
        transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ]
)

normalizer = macenko_normalizer()
img_path = "images/MHIST_aaa.png"
image = Image.open(img_path).convert("RGB")
image_macenko = normalizer(image)

sample_input = transform(image_macenko).unsqueeze(0)
model.cuda()
model.eval()

features = model(sample_input.cuda())

Model Performance Comparison

We report linear evaluation result on six downstream tasks. Top-1 accuracy is shown, with values for models other than Gigapath taken from the RudolfV paper.

ModelPCAMMHISTCRC-100KTIL Det.MSI CRCMSI STADAvg
ResNet50 ImageNet0.8330.8060.8490.9150.6530.6640.787
ViT-L/16 ImageNet0.8520.7960.8470.9240.6690.6710.793
Lunit0.9180.7710.9490.9430.7450.7560.847
CTransPath0.8720.8170.8400.9300.6940.7260.813
Phikon0.9060.7950.8830.9460.7330.7510.836
Virchow0.9330.8340.968----
RudolfV0.9440.8210.9730.9430.7550.7880.871
GigaPath (patch encoder)0.9470.8220.9640.9380.7530.7480.862
EXAONEPath (ours)0.9010.8180.9460.9390.7560.8040.861

Model Comparison Param Model Comparison WSIS
Figure 1. Performance comparison of models based on the number of parameters and the number of WSIs used for training. The average Top-1 accuracy represents the mean linear evaluation performance across six downstream tasks.

License

The model is licensed under EXAONEPath AI Model License Agreement 1.0 - NC

Citation

If you find EXAONEPath useful, please cite it using this BibTeX:

@article{yun2024exaonepath,
  title={EXAONEPath 1.0 Patch-level Foundation Model for Pathology},
  author={Yun, Juseung and Hu, Yi and Kim, Jinhyung and Jang, Jongseong and Lee, Soonyoung},
  journal={arXiv preprint arXiv:2408.00380},
  year={2024}
}

Contact

LG AI Research Technical Support: [email protected]

Significant stargazers

Omar Sanseviero

1,113 followers · starred Sep 2024