Downloads · 30 days
0
lion-ai/MedImageInsights
MedImageInsights is a machine learning model from lion-ai. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This repository provides a simplified implementation for using the MedImageInsight model, an open-source medical imaging embedding model presented in the paper MedImageInsight: An Open-Source Embedding Model for Gener…
Downloads · 30 days
0
Access
Public
Updated Nov 4, 2024
Repo size
2.5 GB
Likes
74
Public
Click a slice to open those files.
.pt2.5 GB · 100%
From the Hugging Face model README
This repository provides a simplified implementation for using the MedImageInsight model, an open-source medical imaging embedding model presented in the paper MedImageInsight: An Open-Source Embedding Model for General Domain Medical Imaging by Noel C. F. Codella et al. The official guide to access the model from Microsoft is quite complicated, and it is arguable whether the model is truly open-source. This repository aims to make it easier to use the MedImageInsight model for various tasks, such as zero-shot classification, image embedding, and text embedding.
What we have done:
Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install
git clone https://huggingface.co/lion-ai/MedImageInsights
To create a virtual env, simply run:
uv sync
Or to run a single script, just run:
uv run example.py
That's it!
See to the example.py file.
Here's an example of how to use the MedImageInsight class for zero-shot classification:
# Initialize classifier
classifier = MedImageInsight(
model_dir="2024.09.27",
vision_model_name="medimageinsigt-v1.0.0.pt",
language_model_name="language_model.pth"
)
# Load model
classifier.load_model()
# Read image
image = base64.encodebytes(read_image("image.png")).decode("utf-8")
# Zero-shot classification
images = [image]
labels = ["normal", "Pneumonia", "unclear"]
results = classifier.predict(images, labels)
print(results)
Run multi-label image classification (without softmax at the end)
# Multilabel classification example
images = [image]
labels = ["normal", "Pneumonia", "Fracture", "Tumor"]
results = classifier.predict(images, labels, multilabel=True)
print(results)
results = classifier.encode(images=images)
print(results["image_embeddings"])
results = classifier.encode(texts=labels)
print(results["text_embeddings"])
uv run fastapi_app.py
Go to localhost:8000/docs to see the swagger.
The application provides endpoints for classification and image embeddings. Images have to be base64 encoded.
This repository is based on the work presented in the paper "MedImageInsight: An Open-Source Embedding Model for General Domain Medical Imaging" by Noel C. F. Codella et al. (arXiv:2410.06542).