GithubHelp home page GithubHelp logo

dewenzeng / positional_cl Goto Github PK

View Code? Open in Web Editor NEW
52.0 52.0 9.0 991 KB

code for paper Positional Contrastive Learning for Volumetric Medical Image Segmentation

Python 97.81% Shell 2.19%
contrastive-learning deep-learning medical-image-segmentation pytorch self-supervised-learning

positional_cl's People

Contributors

dewenzeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

positional_cl's Issues

The hyperparameters for HVSMR supervised learning

It puzzles me how this finetuning works since I can only get ~0.67 on M=6 on HVSMR Dataset using ACDC pretrained model.
My settings are:
--batch_size 4 --epochs 100 --lr 1e-4 --min_lr 5e-6 --initial_filter_size 48 --classes 4 --dataset hvsmr --patch_size 352 352
Could you please provide me your settings for that?

bug report and some notice

pkgs:
batchgenerators 0.23

report bugs:

  1. the same bug @CaiziLee mentioned in cannot reproduce the reported results #3 in dataset/acdc.py occured on dataset/chd.py
  2. the similar bug above occured on dataset/hvsmr.py and dataset/mmwhs.py
    from batchgenerators.dataloading import MultiThreadedAugmenter
    from batchgenerators.transforms import Compose, RndTransform
    from batchgenerators.transforms import SpatialTransform, MirrorTransform
    from batchgenerators.transforms import GammaTransform, ConvertSegToOnehotTransform
    from batchgenerators.transforms import RandomCropTransform
    should be corrected as
    from batchgenerators.dataloading.multi_threaded_augmenter import MultiThreadedAugmenter
    from batchgenerators.transforms.abstract_transforms import Compose, RndTransform
    from batchgenerators.transforms.spatial_transforms import SpatialTransform, MirrorTransform
    from batchgenerators.transforms.color_transforms import GammaTransform
    from batchgenerators.transforms.utility_transforms import ConvertSegToOnehotTransform
    from batchgenerators.transforms.crop_and_pad_transforms import RandomCropTransform

notice:
model = torch.nn.DataParallel(model, device_ids=args.multiple_device_id) in train_contrast.py reported error, which is due to parser.add_argument("--multiple_device_id", type=tuple, default=(0,1)) in myconfig.py
but in fact, when it comes to multiple GPUs, maybe we should name the specific GPUs we request, like

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "2, 3"

in train_contrast.py before the main function.

cannot reproduce the reported results

a very large gap between the reported results and mines, did I miss any important tricks?
The details of my experiments are presented as follows,
1, fix two bugs:
image

2, prepare acdc dataset via generate_acdc.py

3, prepare running scripts:
(1) from scratch:
python train_supervised.py --device cuda:0 --batch_size 10 --epochs 200 --data_dir ./dir_for_labeled_data --lr 5e-4 --min_lr 5e-6 --dataset acdc --patch_size 352 352 --experiment_name supervised_acdc_random_sample_6_ --initial_filter_size 48 --classes 4 --enable_few_data --sampling_k 6;

(2) contrastive learning:
python train_contrast.py --device cuda:0 --batch_size 32 --epochs 300 --data_dir ./dir_for_unlabeled_data --lr 0.01 --do_contrast --dataset acdc --patch_size 352 352 --experiment_name contrast_acdc_pcl_temp01_thresh035_ --slice_threshold 0.35 --temp 0.1 --initial_filter_size 48 --classes 512 --contrastive_method pcl;

python train_contrast.py --device cuda:0 --batch_size 32 --epochs 300 --data_dir ./dir_for_unlabeled_data --lr 0.01 --do_contrast --dataset acdc --patch_size 352 352 --experiment_name contrast_acdc_gcl_temp01_thresh035_ --slice_threshold 0.35 --temp 0.1 --initial_filter_size 48 --classes 512 --contrastive_method gcl;

python train_contrast.py --device cuda:0 --batch_size 32 --epochs 300 --data_dir ./dir_for_unlabeled_data --lr 0.01 --do_contrast --dataset acdc --patch_size 352 352 --experiment_name contrast_acdc_simclr_temp01_thresh035_ --slice_threshold 0.35 --temp 0.1 --initial_filter_size 48 --classes 512 --contrastive_method simclr;

(3) finetuning:
python train_supervised.py --device cuda:0 --batch_size 10 --epochs 100 --data_dir ./dir_for_labeled_data --lr 5e-5 --min_lr 5e-6 --dataset acdc --patch_size 352 352 --experiment_name supervised_acdc_simclr_sample_6_ --initial_filter_size 48 --classes 4 --enable_few_data --sampling_k 6 --restart --pretrained_model_path ./results/contrast_acdc_simclr_temp01_thresh035_2021-12-05_09-43-38/model/latest.pth;

python train_supervised.py --device cuda:1 --batch_size 10 --epochs 100 --data_dir ./dir_for_labeled_data --lr 5e-5 --min_lr 5e-6 --dataset acdc --patch_size 352 352 --experiment_name supervised_acdc_gcl_sample_6_ --initial_filter_size 48 --classes 4 --enable_few_data --sampling_k 6 --restart --pretrained_model_path ./results/contrast_acdc_gcl_temp01_thresh035_2021-12-04_03-46-35/model/latest.pth;

python train_supervised.py --device cuda:1 --batch_size 10 --epochs 100 --data_dir ./dir_for_labeled_data --lr 5e-5 --min_lr 5e-6 --dataset acdc --patch_size 352 352 --experiment_name supervised_acdc_pcl_sample_6_ --initial_filter_size 48 --classes 4 --enable_few_data --sampling_k 6 --restart --pretrained_model_path ./results/contrast_acdc_pcl_temp01_thresh035_2021-12-02_21-48-13/model/latest.pth;

4, experimental results(ubuntu16.04, pytorch1.9, NVIDIA 2080Ti * 2, Dice metric, take sample_k=6 as an example):
image

question on fine-tuning

Hi, I'm trying to run train_supervised.py using acdc dataset. The patchsize used in the pre-training stage is (352,352), as showed in the run_script.sh, the patchsize used in the fine-tuning stage is (512,512) (for chd dataset). I'm wondering what patchsize is selected for acdc dataset, thank you!

Questions on contrastive training

Hi, I'm trying to train the contrastive encoder from scratch on the ACDC data set, however, unlike your result shown on #3, my loss is stuck at 5.5597 from epoch 0 to epoch 30 until I cancelled it due to long time running. I'm wondering if I missed any tricks?

My results:

  1. looks fine on the first several iterations

截屏2022-03-01 下午3 27 47

  1. stucked into 5.5597 in the following 30 epochs

截屏2022-03-01 下午3 29 16

截屏2022-03-01 下午3 29 33

I run the code with:

python3 train_contrast.py --device cuda:0 --batch_size 25 --epochs 300 --data_dir "./dataset/02_08_2022/acdc/unlabeled/" --lr 0.1 --do_contrast --dataset acdc --patch_size 352 352 \
--experiment_name contrast_acdc_pcl_temp01_thresh035 --slice_threshold 0.35 --temp 0.1 --initial_filter_size 48 --classes 512 --contrastive_method pcl

Here I set the batch_size to 25 to avoid the memory crush.

the code of your team (about another MICCAI21 paper)

I would like to congratulate the authors for this outstanding paper!
I am wondering if your team can share the code of another MICCAI21 paper (Federated Contrastive Learning for Volumetric Medical Image Segmentation), both papers will help us a lot for Contrastive Learning in the medical domain.
thanks.

Inquire about PCL training

Dear Zeng

When training the PCL model with the CHD dataset, using the parameters you provided, the GPU utilization is zero most of the time, and fully occupied for a period, making the training speed very slow. I would like to inquire about your training configuration and training time, and whether you have encountered this problem.

thanks!

question on package import

Hi, i'm trying to run the code train_supervised.py, there is something wrong with the package metrics. There is no class named SegmentationMetrics when import this package. I would like to ask how this metrics package should be imported, thank you!

Difficulty reproducing fine-tuning results

Hello! Thank you for the great paper and for providing your code as open source.

I have been having some difficulty reproducing the fine-tuning results from table 1 in the paper. I'm working with the ACDC dataset.

Here are the steps I have followed:

  1. Run generate_acdc.py, yielding two output folders - one for labeled data, one for unlabeled.
  2. Download the provided pretrained ACDC PCL model from google drive.
  3. Run CUDA_VISIBLE_DEVICES=0 python train_supervised.py --device cuda:0 --batch_size 10 --epochs 100 --data_dir <ACDC_dir/labeled_dir> --lr 5e-5 --min_lr 5e-6 --dataset acdc --patch_size 352 352 \ --experiment_name supervised_acdc_pcl_sample_2 --initial_filter_size 48 --classes 4 --enable_few_data --sampling_k 2 --restart --pretrained_model <pretrained_model.pth>.

I am trying to reproduce the table's first column, so am setting sampling_k=2.

I am getting the following validation dice results (at the end of the 100 epochs):

Fold Validation dice
0 0.1878
1 0.2449
2 0.2729
3 0.1103
4 0.1079

Average validation dice = 0.185 << 0.671

Running the same experiment, but setting sampling_k=6 (i.e. the second column) I get an average validation dice = (0.6847 + 0.7170 + 0.5431 + 0.5345 + 0.640) / 5.0 = 0.624 < 0.850

I would appreciate any help or guidance! Please let me know if I am doing something wrong, or if I am interpreting my results incorrectly.

Data preprocessing not work

I tried to use the below script to generate the npy data. However, no npy files are generated.

python generate_acdc.py -i raw_image_dir -out_labeled save_dir_for_unlabeled_data -out_unlabeled save_dir_for_unlabeled_data

Would you please help check? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.