Fine-tuning OpenAI CLIP Model for Image Search on medical images.
PLEASE NOTE: The code in this repository is being provided as-is without any warranty of any kind. While efforts have been made to ensure that the instructions are accurate, some of the underlying software libraries move on a fast update cycle and may have changed, and as a result the code may neither be installable or executable. It is being provided for study purposes only.
training, test and validation data. Since the dataset is for caption prediction, the test folder does not contain any captions. The train and validation folders contains a CSV file of image file names and captions, and all the three folders contain a nested sub-folder containing the images corresponding to each split.$ mkdir -p ImageCLEF2017-CaptionPrediction; cd ImageCLEF2017-CaptionPrediction
$ tree .
|
*-- test/
| |
| +-- CaptionPredictionTesting2017-List.txt
| +-- CaptionPredictionTesting2017/
| |
| +-- test-image-1.jpg
| +-- ... 9,999 more ...
|
+-- training/
| |
| +-- CaptionPredictionTraining2017-Captions.csv
| +-- CaptionPredictionTraining2017/
| |
| +-- training-image-1.jpg
| +-- ... 164,613 more ...
|
+-- validation/
|
+-- CaptionPredictionValidation2017-Captions.csv
+-- ConceptDetectionValidation2017/
|
+-- validation-image-1.jpg
+-- ... 9,999 more ...
| Experiment | k=1 | k=3 | k=5 | k=10 | k=20 |
|---|---|---|---|---|---|
| baseline | 0.42580 | 0.53402 | 0.55837 | 0.57349 | 0.57829 |
| run-1 | 0.69130 | 0.78962 | 0.80113 | 0.80517 | 0.80589 |
| run-2 | 0.71200 | 0.80445 | 0.81519 | 0.81912 | 0.81968 |
| run-3 | 0.34540 | 0.46338 | 0.49253 | 0.51154 | 0.51753 |
| run-4 | 0.78760 | 0.86227 | 0.86870 | 0.87080 | 0.87120 |
| run-5 | 0.80200 | 0.87170 | 0.87743 | 0.87966 | 0.88002 |
The Image Search demo is located on a standalone CPU-only box since we are only doing inference. The corpus of images + captions used is the combination of the training, validation, and unseen test sets provided by ImageCLEF 2017 Caption Prediction challenge. The captions and image vectors are hosted on the Vespa search engine, which provides both BM25 based text search services and HNSW and Cosine similarity based Approximate Nearest Neighbor services.
en_core_web_sm Language Model)Docker -- instructions
Vespa -- instructions
clip-demo as new app in sample-appsimage-search/vespa/src folder to sample-apps/clip-demobash-scripts to point to clip-demo sample applaunch.sh to start docker instancedeploy.sh to deploy clip-demo to Vespastatus.sh to verify Vespa statusPrepare data
Images -- Download ImageCLEF dataset and explode as described in the Fine Tuning section.
$ mkdir CaptionPrediction; cd CaptionPrediction
$ unzip folder structure
Models -- copy over the folder corresponding to the fine-tuned CLIP model from fine-tuning step that contains the pytorch_model.bin file.
Vectors -- use fine-tuned model to generate image vectors.
$ cd fine-tuning
$ python vectorize-images --model_path /path/to/fine-tuned/pytorch_model.bin \
--output-dir /path/to/folder/containing/vector/files/
Load data -- run load-vespa-index.py
$ cd image-search
$ python load-vespa-index.py --image_dir /path/to/CaptionPrediction/folder \
--vector_dir /path/to/folder/containing/vector/files/
A Streamlit based demo illustrates the usage of the trained model for the following use cases.
To run streamlit server, run following command, application will start listening on port 8501.
$ cd image-search
$ streamlit run app.py
11 commits
Python
99.7%
Fine-tuning OpenAI CLIP Model for Image Search on medical images.
PLEASE NOTE: The code in this repository is being provided as-is without any warranty of any kind. While efforts have been made to ensure that the instructions are accurate, some of the underlying software libraries move on a fast update cycle and may have changed, and as a result the code may neither be installable or executable. It is being provided for study purposes only.
training, test and validation data. Since the dataset is for caption prediction, the test folder does not contain any captions. The train and validation folders contains a CSV file of image file names and captions, and all the three folders contain a nested sub-folder containing the images corresponding to each split.$ mkdir -p ImageCLEF2017-CaptionPrediction; cd ImageCLEF2017-CaptionPrediction
$ tree .
|
*-- test/
| |
| +-- CaptionPredictionTesting2017-List.txt
| +-- CaptionPredictionTesting2017/
| |
| +-- test-image-1.jpg
| +-- ... 9,999 more ...
|
+-- training/
| |
| +-- CaptionPredictionTraining2017-Captions.csv
| +-- CaptionPredictionTraining2017/
| |
| +-- training-image-1.jpg
| +-- ... 164,613 more ...
|
+-- validation/
|
+-- CaptionPredictionValidation2017-Captions.csv
+-- ConceptDetectionValidation2017/
|
+-- validation-image-1.jpg
+-- ... 9,999 more ...
| Experiment | k=1 | k=3 | k=5 | k=10 | k=20 |
|---|---|---|---|---|---|
| baseline | 0.42580 | 0.53402 | 0.55837 | 0.57349 | 0.57829 |
| run-1 | 0.69130 | 0.78962 | 0.80113 | 0.80517 | 0.80589 |
| run-2 | 0.71200 | 0.80445 | 0.81519 | 0.81912 | 0.81968 |
| run-3 | 0.34540 | 0.46338 | 0.49253 | 0.51154 | 0.51753 |
| run-4 | 0.78760 | 0.86227 | 0.86870 | 0.87080 | 0.87120 |
| run-5 | 0.80200 | 0.87170 | 0.87743 | 0.87966 | 0.88002 |
The Image Search demo is located on a standalone CPU-only box since we are only doing inference. The corpus of images + captions used is the combination of the training, validation, and unseen test sets provided by ImageCLEF 2017 Caption Prediction challenge. The captions and image vectors are hosted on the Vespa search engine, which provides both BM25 based text search services and HNSW and Cosine similarity based Approximate Nearest Neighbor services.
en_core_web_sm Language Model)Docker -- instructions
Vespa -- instructions
clip-demo as new app in sample-appsimage-search/vespa/src folder to sample-apps/clip-demobash-scripts to point to clip-demo sample applaunch.sh to start docker instancedeploy.sh to deploy clip-demo to Vespastatus.sh to verify Vespa statusPrepare data
Images -- Download ImageCLEF dataset and explode as described in the Fine Tuning section.
$ mkdir CaptionPrediction; cd CaptionPrediction
$ unzip folder structure
Models -- copy over the folder corresponding to the fine-tuned CLIP model from fine-tuning step that contains the pytorch_model.bin file.
Vectors -- use fine-tuned model to generate image vectors.
$ cd fine-tuning
$ python vectorize-images --model_path /path/to/fine-tuned/pytorch_model.bin \
--output-dir /path/to/folder/containing/vector/files/
Load data -- run load-vespa-index.py
$ cd image-search
$ python load-vespa-index.py --image_dir /path/to/CaptionPrediction/folder \
--vector_dir /path/to/folder/containing/vector/files/
A Streamlit based demo illustrates the usage of the trained model for the following use cases.
To run streamlit server, run following command, application will start listening on port 8501.
$ cd image-search
$ streamlit run app.py
11 commits
Python
99.7%