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:

Note: Some of these models require a HuggingFace Token that has been approved by the model owner. The Google model also requires submitters to sign additional Terms of Service.

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.13.7.tar.gz (27.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dpfm_factory-0.13.7.tar.gz
Algorithm Hash digest
SHA256 fe28da017132e37ffaf8b4c9245089e928966a68a983e443c2e8bf2cecf8b8ee
MD5 9b86833283e49e3cabe09066982ef42f
BLAKE2b-256 ef16015dafb001fc4b01949d7a15e3e79149f48208c01fd4b50c10ec334599c1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dpfm_factory-0.13.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6b5f23252a47b034b2f9b9ba12e426360c6f0919a6be32baa6ab8158b3be30a9
MD5 b3221b3b62aefd908f15aa3241a2c629
BLAKE2b-256 d3d594d38468f8140165e7035473567631a61d8116c9ced01a97e84358f5184e

See more details on using hashes here.

Supported by

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