Unsupervised Contrastive Learning of Image Representations from Ultrasound Videos with Hard Negative Mining
This is the official implementation of the UCL-method based on Hard Negative Mining, introduced in our paper https://arxiv.org/abs/2207.13148.
Our code is tested on Python 3.7 and Pytorch 1.3.0, please install the environment via
pip install -r requirements.txt
Note: To run our code you'll need multiple GPUs this code is not designed to run on single GPU systems.
- Video Dataset: To get our Video Dataset(GBUSV) follow the instructions here.
- Image Dataset: To get our Image Dataset(GBCU) follow the instructions here.
We provide the models pretrained on Video Data for 50 epochs.
Method | Downstream Task | Backbone | Pre-trained model | Fine-tuned model (on a single val split) |
---|---|---|---|---|
UCL | Gallbladder Cancer Detection | Resnet50 | pretrain ckpt | finetune ckpt |
UCL | COVID-19 Detection | Resnet50 | pretrain ckpt | - |
The directory structure should be as followed:
Data_64
│ ├── Video_1
│ │ ├── 00000.jpg
| | ├── 00001.jpg
| | ├── 00002.jpg
| | ├── .....
| ├── Video_2
│ │ ├── 00000.jpg
| | ├── 00001.jpg
| | ├── 00002.jpg
| | ├── ....
In the pre-training script some flags which can be experimented if the default configuration doesn't give results:
- moco-t: It selects the temperature used while loss calculation
- soft-nn-t: It selects the temperature used to calculate cross video negative
- single-loss-ncap-support-size: It decides the number of cross video negatives used to form cross video negative used in the loss function
- num-negatives: It selects ths number of intra video negatives to be used
bash scripts/pretrain_gb.sh <Video_Data_path>
bash scripts/finetuning_gb.sh <path_to_train_split_txt_file> <path_to_val_split_txt_file> <path_to_pretrained_model> <path_for_saving_finetuned_model> <gpu_id>
bash scripts/evaluate_gb.sh <path_to_train_split_txt_file> <path_to_val_split_txt_file> <path_to_pretrained_model> <gpu_id>
Please follow instructions on USCL Repo to get these datasets.
- After Downloading the butterfly dataset make sure the frames in each video follow the naming convention as described in Data Preparation section of this README.
- Run the command:
bash scripts/pretrain_ucl_butterfly.sh <path_to_butterfly_data>
For this we have followed the evaluation mechanism as proposed in USCL, the script modified for our proposed model can be found here.
Steps to run this script:
- Setup environment and code from USCL repo.
- Place Our Evaluation Script in eval_pretrained_model directory of USCL repo.
- Run the command:
python eval_ucl_pocus.py --path <model_path> --gpu <gpu_id>
The codebase is based on CycleContrast and MoCo.