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

Model weights · MedMLX

RadImageNet encoder features from radiology images
Input Output
2D image Pooled and spatial features

Weights: one file per backbone, 28 MB (DenseNet121), 87 MB (InceptionV3), 94 MB (ResNet50) or 218 MB (InceptionResNetV2). Peak MLX memory for a 1929×2207 chest radiograph: 0.11 GB (DenseNet121), 0.18 GB (InceptionV3), 0.19 GB (ResNet50) and 0.44 GB (InceptionResNetV2).

Use with MedMLX

The MedMLX MCP server is the lowest-friction way to use this package. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run radimagenet-resnet50, radimagenet-densenet121, radimagenet-inceptionv3 and radimagenet-inceptionresnetv2 for you.

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.

Install

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

Run

Each backbone has its own registered model ID: radimagenet-resnet50, radimagenet-densenet121, radimagenet-inceptionv3 and radimagenet-inceptionresnetv2. Their runners take the same arguments:

from radimagenet_mlx.medmlx import resnet50

result = resnet50(image_path="image.png", output_dir="outputs")

Omitting weights_path downloads only the selected backbone from MedMLX/radimagenet-mlx into the shared MedMLX cache on first use; interrupted downloads resume and later runs work offline. With MedMLX installed, medmlx setup radimagenet-resnet50 downloads it ahead of time. To use your own copy, pass a folder containing the matching file (RadImageNet-ResNet50_notop.safetensors, RadImageNet-DenseNet121_notop.safetensors, RadImageNet-InceptionV3_notop.safetensors or RadImageNet-IRV2_notop.safetensors) as weights_path. details.weights_revision records the downloaded commit, or null for a folder without a MedMLX download record.

Inputs and outputs

Argument Meaning
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 File Contents
features_npy features.npy float32 (1, C) average-pooled vector
spatial_features_npy spatial_features.npy float32 (1, H, W, C) last spatial map
features_json features.json Run metadata, also returned as details

Pooled widths are 2048 for ResNet50 and InceptionV3, 1024 for DenseNet121 and 1536 for InceptionResNetV2. The spatial maps are conv5_block3_out, relu, mixed10 and conv_7b_ac. The published checkpoints declare 224×224 inputs, so ResNet50 and DenseNet121 give 7×7 maps and the Inception families 5×5. A checkpoint with a classifier head also writes predictions.npy; the published encoders have none.

Images are prepared as in the upstream RadImageNet example: RGB, nearest-neighbour resize to the checkpoint's input size, Caffe-style BGR mean subtraction, then scaling by 1/255. Outputs that alias the input or each other are refused. Missing or unreadable images raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError.

Local weights

Download one of the native weights and pass the file:

from huggingface_hub import hf_hub_download
from radimagenet_mlx.medmlx import run

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

The safetensors file must contain float32 MLX-layout weights and declarative model_config graph metadata. The published bundle contains four encoders without classification heads. Classifier predictions require a checkpoint that includes a classifier. run detects the backbone, or takes backbone="resnet50", "densenet121", "inceptionv3" or "inceptionresnetv2".

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 only the declarative graph metadata and float32 tensors; it never runs Keras or serialized Python, and it does not authenticate where a checkpoint came from. Inference needs Apple Silicon with Metal and has no CPU fallback.

License

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

For research and education. Outputs require human review.

Metadata

Release files for radimagenet-mlx 0.3.4

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.3.4
File Size Uploaded Provenance Actions
radimagenet_mlx-0.3.4.tar.gz 27.3 kB Without provenance Details for radimagenet_mlx-0.3.4.tar.gz

Built distribution (wheel)

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

Total release size: 60.5 kB

Release files / radimagenet_mlx-0.3.4.tar.gz

Download URL radimagenet_mlx-0.3.4.tar.gz
Size 27.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d6f6e16fbdfd6add3c8f37986a2228e4aae2365c0c374b8beb6d00694f1b8ade
BLAKE2b-256 checksum
How to use checksums
8bbd2a86fd2592e5616c54785f4a4aab9cbffbe0c074d08cccf9bdf13161049a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.4-py3-none-any.whl

Download URL radimagenet_mlx-0.3.4-py3-none-any.whl
Size 33.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f17447b63a24fc793d087f8815ecb288c5c249490dace4a275191b8613a6316
BLAKE2b-256 checksum
How to use checksums
25f4935ebf4e8ae22e7cc4634b92b45917de0cd163da41d987e72109018598ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.4

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