Skip to main content

Med-IM: One-Line Code to Get SoTA Pre-trained Medical Image Models

x x

A collection of pre-trained medical image models in PyTorch. This repository aims to provide a unified and easy-to-use interface for comparing and deploying these models.

Supported Models

  • STU-Net (STU-Net-S, STU-Net-B, STU-Net-L, STU-Net-H) pre-trained on TotalSegmentator, CT-ORG, FeTA21, BraTS21 (more datasets are WIP).
  • SAM-Med3D (SAM-Med3D) pre-trained on SA-Med3D-140K.
  • Other pre-trained medical image models are WIP. (You can request support for your model in Issues.)

Quick Start

Setup Environment

You can use this cmd to install this toolkit via pip:

pip install medim

For developers, you can install in the editable mode via:

git clone https://github.com/uni-medical/MedIM.git
cd MedIM
pip install -e .

Example Usage

First, let us import medim.

import medim

You have four ways to create a PyTorch-compatible model with create_model:

1. use models without pretraining

model = medim.create_model("STU-Net-S") 

2. use local checkpoint

model = medim.create_model(
            "STU-Net-S",
            pretrained=True,
            checkpoint_path="../tests/data/small_ep4k.model") 

3. use checkpoint pre-trained on validated datasets (will automatically download it from HuggingFace)

model = medim.create_model("STU-Net-B", dataset="BraTS21")

4. use HuggingFace url (will automatically download it from HuggingFace)

model = medim.create_model(
            "STU-Net-S",
            pretrained=True,
            checkpoint_path="https://huggingface.co/ziyanhuang/STU-Net/blob/main/small_ep4k.model") 

Tips: you can use MEDIM_CKPT_DIR environment variable to set custom path for medim model downloading from huggingface.

Then, you can use it as you like.

input_tensor = torch.randn(1, 1, 128, 128, 128)
output_tensor = model(input_tensor)
print("Output tensor shape:", output_tensor.shape)

More examples are in examples.

Roadmap & TO-DO

  • support more pre-training of STU-Net on different datasets.
  • support more pre-trained medical image models.
  • An easy-to-use interface compatible with MONAI/nnU-Net is still under development. Once developed, you will be able to deploy medical image models more elegantly within the Python/PyTorch ecosystem.

Metadata

Release files for medim 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medim 0.1.2
File Size Uploaded Provenance Actions
medim-0.1.2.tar.gz 28.5 kB Without provenance Details for medim-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for medim 0.1.2
File Interpreter ABI Platform Actions
medim-0.1.2-py3-none-any.whl Python 3 none any Details for medim-0.1.2-py3-none-any.whl

Total release size: 55.8 kB

Release files / medim-0.1.2.tar.gz

Download URL medim-0.1.2.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4dabea6faf8f89b80b064eca67580b483164c0be8b50b70880e2dd5e2e0929b6
BLAKE2b-256 checksum
How to use checksums
f64eedfc845fe72247668c1f43b306cae7f719d834279496d823d67cf6506b88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / medim-0.1.2-py3-none-any.whl

Download URL medim-0.1.2-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c08a84718aa7ccb1494ccdee781785f955daecb915ba15b2db77455137e503fc
BLAKE2b-256 checksum
How to use checksums
ed5bce521372626f80a9fa9c36379eb2ad591c075cb937c03cb0efeb9380e966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for medim 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page