Code Repository for AAAI23 Paper "Weakly-Supervised Semantic Segmentation for Histopathology Images Based on Dataset Synthesis and Feature Consistency Constraint"
If you are from China Mainland, you can refer to the gitee repo https://gitee.com/vison307/PistoSeg.
Code tested on
- Ubuntu 18.04
- A single Nvidia GeForce RTX 3090
- Python 3.8
- Pytorch 1.12.1
- Pytorch Lightning 1.7.1
Please use the following command to install the dependencies:
conda env create -f environment.yaml
-
Download the WSSS4LUAD dataset and put it in ./data/WSSS4LUAD
-
Download the BCSS-WSSS dataset and put it in ./data/BCSS-WSSS (Thanks to Han et. al)
-
Download the ImageNet-pretrained ResNet weight
ilsvrc-cls_rna-a1_cls1000_ep-0001.params
from SEAM repository and put it in ./weights/ilsvrc-cls_rna-a1_cls1000_ep-0001.params -
Download the CAM model's weights
res38d.pth
from OEEM repository and put it in ./weights/res38d.pth
Please refer to the OEEM readme in ./OEEM/README.md
Or you can use the pre-generated CAMs (in AAAI23/{dataset}/data/CAM/train.zip) and unzip and put them in ./data/WSSS4LUAD/CAM/train and ./data/BCSS-WSSS/CAM/train.
-
Assure that the CAM of the training set is put into ./data/WSSS4LUAD/CAM/train (in .npy format)
-
Split the validation and test dataset with
split_validation.ipynb
to produce 224x224 regular-shaped patches -
Prepare the synthesized dataset and background mask with
create_dataset.ipynb
-
Run
bash run.sh
-
Assure that the CAM of the training set is put into ./data/BCSS-WSSS/CAM/train (in .npy format)
-
Prepare the synthesized dataset with
create_dataset_bcss.ipynb
-
run
bash run-bcss.sh
Due to a disaster to the server, the original weights of the results provided in the paper are lost. So the current codes and weights are re-implemented and re-trained. The results are a bit different from the original ones (but slightly improved in mIoU). The overall performance is still similar.
- Test mIoU: 0.7530
- Test fwIoU: 0.7582
- Test tissue IoU: [0.7991 0.7020 0.7580] - [TUM, STR, NOM]
- Test mIoU: 0.7075
- Test fwIoU: 0.7576
- Test tissue IoU: [0.8144 0.7446 0.6063 0.6645] - [TUM, STR, LYM, NEC]
We tried our best to ensure the reproducibility of the results, but since the torch.nn.functional.interpolate
function is not deterministic, the results may be different over runs. If you want to fully reproduce the results, you can use the following weights (code: yj84) (preliminary segmentation epoch=*.ckpt
, refining ResNet38-RFM.pth
, and precise segmentation segmentation_log/epoch=*.ckpt
) and intermediate results (Generated CAM data/CAM/train.zip
and Refined Masks refine/CAM.zip
). Training logs are also provided for reference.
If you find our code helpful, please cite as follows:
@inproceedings{fang2023weakly, title={Weakly-supervised semantic segmentation for histopathology images based on dataset synthesis and feature consistency constraint}, author={Fang, Zijie and Chen, Yang and Wang, Yifeng and Wang, Zhi and Ji, Xiangyang and Zhang, Yongbing}, booktitle={Proceedings of the AAAI Conference on Artificial Intelligence}, volume={37}, number={1}, pages={606--613}, year={2023} }