Skip to main content

Helper scripts for digital pathology foundation models

Project description

dpfm_factory

dpfm_factory is a Python package that provides a factory function to easily load different machine learning models and their associated preprocessing pipelines from Hugging Face. This package is particularly useful in the digital and computational pathology domains, where it is crucial to work with various specialized models.

Features

  • Easy Model Loading: Load machine learning models and their preprocessing pipelines with a simple factory function.
  • Hugging Face Integration: Seamlessly integrates with Hugging Face to authenticate and load models.
  • Custom Environment Variables: Supports loading environment variables from a .env file for sensitive data like tokens.

Installation

To install the package directly from GitHub, use the following command:

pip install git+https://github.com/Steven-N-Hart/dpfm_factory

Ensure that you have all necessary dependencies listed in the requirements.txt file. Alternatively, clone the repository and install the package locally:

git clone https://github.com/Steven-N-Hart/dpfm_factory
cd dpfm_factory
pip install -r requirements.txt
pip install .

Usage

Setup

Before using the package, make sure to create a .env file in the root of your project directory with your Hugging Face token:

HUGGINGFACE_TOKEN=your_huggingface_token_here

Example Usage

Here’s an example of how to use the model_factory function to load a model and its associated processor:

from dpfm_factory.model_runners import model_factory

# Specify the model you want to load
model_name = 'MahmoodLab/conch'

# Load the model, processor, and the function to get image embeddings
model, processor, get_image_embedding = model_factory(model_name)

# Example usage with an image (replace 'your_image' with actual image data)
image_embedding = get_image_embedding(your_image)

print("Image Embedding:", image_embedding)

Supported Models

The model_factory function currently supports the following models:

  • owkin/phikon
  • paige-ai/Virchow2
  • MahmoodLab/conch
  • prov-gigapath/prov-gigapath
  • LGAI-EXAONE/EXAONEPath
  • histai/hibou-L
  • histai/hibou-b

Error Handling

If an unsupported model name is provided, the model_factory will raise a NotImplementedError. For example:

try:
    model, processor, get_image_embedding = model_factory('unsupported/model_name')
except NotImplementedError as e:
    print(e)

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpfm_factory-0.8.3.tar.gz (27.9 MB view details)

Uploaded Source

Built Distribution

dpfm_factory-0.8.3-py3-none-any.whl (27.9 MB view details)

Uploaded Python 3

File details

Details for the file dpfm_factory-0.8.3.tar.gz.

File metadata

  • Download URL: dpfm_factory-0.8.3.tar.gz
  • Upload date:
  • Size: 27.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for dpfm_factory-0.8.3.tar.gz
Algorithm Hash digest
SHA256 b406032c33ae8149e1e07e42a91f56ab4cb88bc4e438aaf2827bd8f9fcb12b2f
MD5 edd5c2d1865f8b0af72e33eef1a37eb6
BLAKE2b-256 515a54b71bd31e6d5d56b1e1b6f04e5a94ef3540a97986efa2fcdd6c77075b66

See more details on using hashes here.

File details

Details for the file dpfm_factory-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: dpfm_factory-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 27.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for dpfm_factory-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e478efc2cbbb121773abfcb3b4cc614f32db6ceccfb6019721c0b030e339296c
MD5 6da1d6d9abb755905a29d4c8c81afa08
BLAKE2b-256 35fc1e3f23407354543673b9c933d0133337299cd6c7d51a1e422ec1777fc0ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page