Giter Club home page Giter Club logo

flair's Introduction

FLAIR: A Foundation LAnguage Image model of the Retina


A Foundation LAnguage Image model of the Retina (FLAIR):
Encoding expert knowledge in text supervision
Julio Silva-Rodriguez1, Hadi Chakor2, Riadh Kobbi2, Jose Dolz1, Ismail Ben Ayed1
1LIVIA - ETS Montreal, 2DIAGNOS Inc.
| Project | Paper | Code | Tutorials |

Install FLAIR

  • Install in your enviroment a compatible torch version with your GPU. For example:
conda create -n flair_env python=3.8 -y
conda activate flair_env
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
  • Install FLAIR library.
pip install git+https://github.com/jusiro/FLAIR.git

Usage

from PIL import Image
import numpy as np

# Import FLAIR
from flair import FLAIRModel

# Set model
model = FLAIRModel(from_checkpoint=True)

# Load image and set target categories 
# (if the repo is not cloned, download the image and change the path!)

image = np.array(Image.open("./documents/sample_macular_hole.png"))
text = ["normal", "healthy", "macular edema", "diabetic retinopathy", "glaucoma", "macular hole",
        "lesion", "lesion in the macula"]

# Forward FLAIR model to compute similarities
probs, logits = model(image, text)

print("Image-Text similarities:")
print(logits.round(3)) # [[-0.32  -2.782  3.164  4.388  5.919  6.639  6.579 10.478]]
print("Probabilities:")
print(probs.round(3))  # [[0.      0.     0.001  0.002  0.01   0.02   0.019  0.948]]

Note: problems during automatic pre-trained weights download

If you encounter any issue while downloading the pre-trained weights (i.e. from_checkpoint=True), you can manually download the weights from the following links (see Table), unzip the file, and store them at: ./flair/modeling/flair_pretrained_weights/[ID].pth.

Backbone ID
ResNet-50 flair_resnet LINK

Pre-training and transferability

In the following, we present the scripts for model pre-training and transferability. To use them, we recommend cloning the whole repository.

git clone https://github.com/jusiro/FLAIR.git
cd FLAIR
pip install -r requirements.txt

๐Ÿ“ฆ Foundation model pre-training

  • Define the relative paths for datasets and dataframes in ./local_data/constants.py.

  • Prepare the FUNDUS assembly dataset - check ./local_data/prepare_partitions.py to prepare the dataframes.

01_EYEPACS 08_ODIR-5K 15_APTOS 22_HEI-MED 29_AIROGS 36_ACRIMA
02_MESIDOR 09_PAPILA 16_FUND-OCT 23_HRF 30_SUSTech-SYSU 37_DeepDRiD
03_IDRID 10_PARAGUAY 17_DiaRetDB1 24_ORIGA 31_JICHI
04_RFMid 11_STARE 18_DRIONS-DB 25_REFUGE 32_CHAKSU
05_1000x39 12_ARIA 19_Drishti-GS1 26_ROC 33_DR1-2
06_DEN 13_FIVES 20_E-ophta 27_BRSET 34_Cataract
07_LAG 14_AGAR300 21_G1020 28_OIA-DDR 35_ScarDat
  • Vision-Language Pre-training.
python main_pretrain.py --augment_description True --balance True --epochs 15 --batch_size 128 --num_workers 6

๐Ÿ“ฆ Transferability to downstream tasks/domains

  • Define the relative paths for datasets and dataframes in ./local_data/constants.py.
  • Prepare the experiment setting for the target dataset - we used ./local_data/experiments.py to store them.
if experiment == "02_MESSIDOR":
    setting = {"dataframe": PATH_DATAFRAME_TRANSFERABILITY_CLASSIFICATION + "02_MESSIDOR.csv",
               "task": "classification",
               "targets": {"no diabetic retinopathy": 0,
                           "mild diabetic retinopathy": 1,
                           "moderate diabetic retinopathy": 2,
                           "severe diabetic retinopathy": 3,
                           "proliferative diabetic retinopathy": 4}}
  • Zero-shot (no adaptation).
python main_transferability.py --experiment 02_MESSIDOR --method zero_shot --load_weights True --domain_knowledge True  --shots_train 0% --shots_test 100% --project_features True --norm_features True --folds 1 
  • Linear Probing.
python main_transferability.py --experiment 02_MESSIDOR --method lp --load_weights True --shots_train 80% --shots_test 20% --project_features False --norm_features False --folds 5 

Citation

If you find this repository useful, please consider citing this paper:

@article{FLAIR2023,
  title={A Foundation LAnguage-Image model of the Retina (FLAIR): Encoding expert knowledge in text supervision},
  author={Julio Silva-Rodriguez and Hadi Chakor and Riadh Kobbi and Jose Dolz and Ismail Ben Ayed},
  journal={ArXiv Preprint},
  year={2023}
}

License

flair's People

Contributors

jusiro 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flair's Issues

downloading link for the 05_1000x39 dataset

Hello, I am very interested in your article and have reproduced it. We mainly tested two single disease, DR and macular membrane-ERM, and performed well on DR. However, there were many missed diagnoses on the macular membrane dataset, possibly due to a small number of datasets. 04_ RFMid and 05_ 1000x39 datasets all contains macular membrane ERM and 05_ 1000x39, we only used 04_ The RFMid dataset, and cannot download the dataset 05_1000x39. we still want to use 05_1000x39 to test macular membrane-ERM disease. Could you send download link for 05_1000x39 dataset? We look forward to and thank you very much for your reply!

can't find csv files in the downloaded datasets?

Hi, thanks for your great work. I'm following the prepare_partitions.py to process the dataset, but these functions requires loading csv files, however the original datasets didn't provide these csv files. Can you help me out?

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.