Skip to main content

radimagenet-mlx

Extract radiology-image features with native MLX RadImageNet encoders: ResNet50, DenseNet121, InceptionV3 and InceptionResNetV2.

PyPI Python License Apple Silicon Hugging Face MedMLX

RadImageNet encoder features from radiology images
Input Output
2D image Pooled and spatial features
Model Backbone Weights download Peak MLX memory Measured on
radimagenet-densenet121 DenseNet121 28 MB 0.11 GB 1929×2207 chest radiograph
radimagenet-inceptionv3 InceptionV3 87 MB 0.18 GB 1929×2207 chest radiograph
radimagenet-resnet50 ResNet50 94 MB 0.19 GB 1929×2207 chest radiograph
radimagenet-inceptionresnetv2 InceptionResNetV2 218 MB 0.44 GB 1929×2207 chest radiograph

Each backbone downloads its own weights file. Peak memory is for a 1929×2207 chest radiograph.

Install

uv venv --python 3.13
source .venv/bin/activate
uv pip install "radimagenet-mlx>=0.4.2"

Run

Each backbone has its own model ID: radimagenet-resnet50, radimagenet-densenet121, radimagenet-inceptionv3 and radimagenet-inceptionresnetv2.

from radimagenet_mlx import run

result = run(model="radimagenet-resnet50", image_path="image.png", output_dir="outputs")

Only the selected backbone's weights download from MedMLX/radimagenet-mlx on first use; medmlx setup radimagenet-resnet50 downloads them ahead of time. For local weights, pass a folder containing the backbone's weights file as weights_path.

Inputs and outputs

Argument Meaning
model One of the four model IDs above
image_path One Pillow-readable 2D image; a multi-frame file uses its first frame
output_dir Directory for the outputs
weights_path Optional folder containing the backbone's .safetensors file
overwrite False by default, which refuses to replace existing outputs
output_selection "all" (default), or "pooled" to write only features.npy and metadata
Output role File Contents
features features.npy float32 (1, C) average-pooled vector
spatial_features spatial_features.npy float32 (1, H, W, C) last spatial map
metadata features.json Run metadata, also returned as details

The result also holds an artifacts entry for each output: feature_tensor for the arrays and report for the metadata.

The published checkpoints declare 224×224 inputs:

Backbone Weights file Pooled width Spatial map Map size
ResNet50 RadImageNet-ResNet50_notop.safetensors 2048 conv5_block3_out 7×7
DenseNet121 RadImageNet-DenseNet121_notop.safetensors 1024 relu 7×7
InceptionV3 RadImageNet-InceptionV3_notop.safetensors 2048 mixed10 5×5
InceptionResNetV2 RadImageNet-IRV2_notop.safetensors 1536 conv_7b_ac 5×5
  • A checkpoint with a classifier head also writes predictions.npy; the published encoders have none.
  • Preprocessing follows the upstream RadImageNet example: RGB, nearest-neighbor resize to the checkpoint's input size, Caffe-style BGR mean subtraction, then scaling by 1/255.
  • 8-bit images only: the RGB step is Pillow's conversion, as in Keras. It clips 16-bit, 32-bit and float pixels to 0–255 without rescaling, so a 16-bit radiograph becomes almost uniformly white. Save such images as 8-bit first.
  • Output paths must differ from the input and from each other.
  • Missing or unreadable images raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError.

Several images

load_model loads one backbone and keeps it loaded until closed. Its run takes the same arguments as run without model and weights_path; run_batch streams model batches with one output folder per image, each in the single-image format. It checks every path first, publishes images in input order and keeps completed images if a later one fails.

from radimagenet_mlx import load_model

with load_model(model="radimagenet-resnet50") as model:
    for result in model.run_batch(
        image_paths=["slice1.png", "slice2.png"],
        output_dirs=["out/slice1", "out/slice2"],
        batch_size=2,
        output_selection="pooled",
    ):
        print(result["outputs"]["features"])

A checkpoint with a fixed batch size uses that size: it must not exceed batch_size and must divide the number of images.

Local weights

Download one of the native weights and pass the folder that contains the file:

from pathlib import Path

from huggingface_hub import hf_hub_download
from radimagenet_mlx import run

weights = hf_hub_download(
    "MedMLX/radimagenet-mlx", "RadImageNet-ResNet50_notop.safetensors",
    revision="fd1c2663266360c899211c9a23ffc24f805d282a",
)
result = run(
    model="radimagenet-resnet50",
    image_path="slice.png",
    weights_path=Path(weights).parent,
    output_dir="features",
)
print(result["outputs"]["features"])

weights_path is always a folder that holds the backbone's published file name, listed above. The safetensors file must contain float32 MLX-layout weights and declarative model_config graph metadata; its detected architecture must match model. The published bundle contains four encoders without classification heads. Classifier predictions require a checkpoint that includes a classifier.

Python API

from pathlib import Path
from radimagenet_mlx import RadImageNetResNet50Mlx, prepare_image

encoder = RadImageNetResNet50Mlx(Path("RadImageNet-ResNet50_notop.safetensors"))
images = prepare_image(Path("slice.png"))  # float32 NHWC, shape (1, 224, 224, 3)
features = encoder(images)  # (1, 2048)
spatial = encoder.spatial_features(images)  # (1, 7, 7, 2048)
  • RadImageNetMlx(checkpoint_file) detects the architecture; the family classes also enforce it.
  • extract(images) returns spatial features, pooled features and any classifier predictions in one pass, and predict refuses checkpoints without a classifier.
  • Encoders take prepared BxHxWx3 arrays and do not check them for finite values.
  • Checkpoints without a fixed input size default to 224×224 for ResNet50 and DenseNet121 and 299×299 for the Inception families (minimum 32 and 75).
  • The loader reads graph metadata and float32 tensors without running Keras or serialized Python.

Use with MedMLX

Use the MedMLX MCP server to run radimagenet-resnet50, radimagenet-densenet121, radimagenet-inceptionv3 and radimagenet-inceptionresnetv2 from an MCP client. Weights download on first use.

uv tool install --python 3.13 "medmlx[vision,mcp]"
MEDMLX="$(uv tool dir --bin --color never)/medmlx"
mkdir -p "$HOME/medmlx-work"
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"

For Codex, use codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work". Other MCP clients take the same command and arguments. The same install provides the medmlx CLI, for example medmlx describe radimagenet-resnet50.

For AI agents: prefer the MedMLX MCP tools (list_models, describe_model, model_readiness, run_model, get_job) over writing Python against this package.

License

Apache-2.0. See third-party notices. Model weights retain their publisher terms.

Metadata

Release files for radimagenet-mlx 0.4.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 radimagenet-mlx 0.4.2
File Size Uploaded Provenance Actions
radimagenet_mlx-0.4.2.tar.gz 28.8 kB Without provenance Details for radimagenet_mlx-0.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for radimagenet-mlx 0.4.2
File Interpreter ABI Platform Actions
radimagenet_mlx-0.4.2-py3-none-any.whl Python 3 none any Details for radimagenet_mlx-0.4.2-py3-none-any.whl

Total release size: 63.5 kB

Release files / radimagenet_mlx-0.4.2.tar.gz

Download URL radimagenet_mlx-0.4.2.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7d1d48485213b8e8f8f19f10dd151af5e7b21eb4edccd5d64bf2bb6efeeceec5
BLAKE2b-256 checksum
How to use checksums
1f7a4a15fdee6e802fb48d8a73690bd49f10cef36daf8dac122c037be74aec2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / radimagenet_mlx-0.4.2-py3-none-any.whl

Download URL radimagenet_mlx-0.4.2-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d82d6f3712222e642f0fd045dbb782c112ef41166ff5f20b75bf618223a0eb4
BLAKE2b-256 checksum
How to use checksums
f8a97f5ea8f85e3f6252bf2189ee3b62a6e0977d169d02cdc35d93e2fa77f276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for radimagenet-mlx 0.4.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