https://github.com/camellia-hz/stoma-clip

https://github.com/camellia-hz/stoma-clip

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: Camellia-hz
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 7.06 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

PMC-CLIP

Quick Start Demo Dataset and Model

The dataset and checkpoint is available at Huggingface, Baidu Cloud(key: 3iqf).

📢 We provide the extracted image encoder and text encoder checkpoint in Huggingface, and a quick start demo on how to use them in encoding image and text input. Check this notebook!

Quick Start Inference

We offer a quick start demo on how to use the image and text encoder of PMC-CLIP. Check this notebook!

Train and Evaluation

Repo Structure bash src/: |--setup.py |--pmc_clip/ | |--loss/ | |--model/: PMC-CLIP model and variants | |--model_configs/ | |--factory.py: Create model according to configs | |--transform.py: data augmentation |--training/ | |--main.py | |--scheduler.py: Learning rate scheduler | |--train.py | |--evaluate.py | |--data.py | |--params.py docs/: project pages

1. Create Environment

```bash conda create -n pmcclip python=3.8 conda activate pmcclip

pip install -r requirements.txt

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

python setup.py develop # install pmc_clip with dev mode ```

2. Prepare Dataset

Download from Huggingface, Baidu Cloud(key: 3iqf). Or follow the Pipeline of PMC-OA Development if you want to start from scratch.

3. Training

Single GPU bash python -m training.main \ --dataset-type "csv" --csv-separator "," --save-frequency 5 \ --report-to tensorboard \ --train-data="path/to/train.csv" --val-data="path/to/valid.csv" \ --csv-img-key image --csv-caption-key caption \ --warmup 500 --batch-size=8 --lr=1e-4 --wd=0.1 --epochs=100 --workers=8 \ --model RN50_fusion4 --hugging-face --mlm --crop-scale 0.5

Multi GPU bash CUDA_VISIBLE_DEVICES=0,1 torchrun --nproc_per_node=2 --rdzv_endpoint=$HOSTE_NODE_ADDR -m training.main \ --dataset-type "csv" --csv-separator "," --save-frequency 5 \ --report-to tensorboard \ --train-data="path/to/train.csv" --val-data="path/to/valid.csv" \ --csv-img-key image --csv-caption-key caption \ --warmup 500 --batch-size=128 --lr=1e-4 --wd=0.1 --epochs=100 --workers=8 \ --model RN50_fusion4 --hugging-face --mlm --crop-scale 0.5

4. Evaluation

Load checkpoint and eval on 2k samples from testset.

bash python -m training.main \ --dataset-type "csv" --csv-separator "," --report-to tensorboard \ --val-data="path/to/test.csv" \ --csv-img-key image --csv-caption-key caption \ --batch-size=32 --workers=8 \ --model RN50_fusion4 --hugging-face --mlm --crop-scale 0.1 \ --resume /path/to/checkpoint.pt \ --test-2000

Also we provide automatic ways to load model weights from huggingface repo.

| Model | URL | | --- | --- | | PMCCLIP:beta | https://huggingface.co/datasets/axiong/pmcoa_beta/blob/main/checkpoint.pt |

Take PMCCLIP:beta checkpoint as an example: ```bash python -m training.main \ --dataset-type "csv" --csv-separator "," --report-to tensorboard \ --val-data="path/to/test.csv" \ --csv-img-key image --csv-caption-key caption \ --batch-size=32 --workers=8 \ --model RN50fusion4 --hugging-face --mlm --crop-scale 0.1 \ --resume "PMC_CLIP:beta" \ --test-2000 ```

Acknowledgement

The code is based on OpenCLIP and M3AE. We thank the authors for their open-sourced code and encourage users to cite their works when applicable.

Note that our code don't supported tools like horovod, wandb in OpenCLIP. But we keep the code from OpenCLIP for consistency.

Contribution

Please raise an issue if you need help, any contributions are welcomed.

TODO

  • [ ] Compatibility testing on more env settings
  • [ ] Support for horovod, wandb

Cite

bash @article{lin2023pmc, title={PMC-CLIP: Contrastive Language-Image Pre-training using Biomedical Documents}, author={Lin, Weixiong and Zhao, Ziheng and Zhang, Xiaoman and Wu, Chaoyi and Zhang, Ya and Wang, Yanfeng and Xie, Weidi}, journal={arXiv preprint arXiv:2303.07240}, year={2023} }

The paper has been accepted by MICCAI 2023. bash @inproceedings{lin2023pmc, title={Pmc-clip: Contrastive language-image pre-training using biomedical documents}, author={Lin, Weixiong and Zhao, Ziheng and Zhang, Xiaoman and Wu, Chaoyi and Zhang, Ya and Wang, Yanfeng and Xie, Weidi}, booktitle={MICCAI}, year={2023} }

Owner

  • Name: 白山茶
  • Login: Camellia-hz
  • Kind: user

GitHub Events

Total
  • Watch event: 1
  • Push event: 2
  • Create event: 2
Last Year
  • Watch event: 1
  • Push event: 2
  • Create event: 2

Dependencies

requirements.txt pypi
  • braceexpand *
  • ftfy *
  • jsonlines *
  • pandas *
  • pytorch >=1.9.0
  • regex *
  • tensorboard *
  • timm *
  • torchvision *
  • tqdm *
  • transformers *
  • webdataset *
setup.py pypi
  • ftfy *
  • regex *
  • torch *
  • torchvision *
  • tqdm *
  • transformers *