lung-nodule-mlx
Detect lung nodule candidates in 3D chest CT with MONAI RetinaNet and native MLX.
Top detection on a LUNA16 chest CT, CC BY 4.0.
| Input | Output |
|---|---|
| 3D chest CT · NIfTI | Candidate boxes and scores in RAS mm |
| Model | Weights download | Peak MLX memory | Measured on |
|---|---|---|---|
lung-nodule |
85 MB | 5.9 GB | 512×512×281 chest CT resampled to the model grid |
Install
uv venv --python 3.13
source .venv/bin/activate
uv pip install "lung-nodule-mlx>=0.3.0"
Run
from lung_nodule_mlx import run
result = run(image_path="ct.nii.gz", output_dir="out")
print(result["outputs"]["detections"])
Weights download from MedMLX/retinanet-lung-nodule-mlx on first use; medmlx setup lung-nodule
downloads them ahead of time. For local weights, pass a folder containing
network.safetensors as weights_path.
Inputs and outputs
| Argument | Meaning |
|---|---|
image_path |
One scalar 3D chest CT in NIfTI, in Hounsfield units, with mm, meter or micron spatial units; unspecified units are taken as mm, as MONAI does |
output_dir |
Directory for detections.json and bundle_detections.json; created if missing |
weights_path |
Optional folder containing network.safetensors |
overwrite |
False by default; existing outputs are replaced only when True |
resample_raw_input |
True by default: resamples to the bundle's 0.703125 × 0.703125 × 1.25 mm grid first, so ordinary CT works. False requires input already on that grid |
resample_raw_input |
Preprocessing |
|---|---|
True (default) |
Resamples to the bundle grid first |
False |
The bundle's pre-resampled mode: reorients to RAS and scales intensities without resampling. Rejects images whose voxel axes are more than 1e-3 mm from the bundle grid or sheared, the cases where the bundle's resampling would change the image |
Spatial units are converted to millimetres; unspecified units are taken as millimetres, as the bundle's MONAI readers do. DICOM series are not read.
| Output | Content |
|---|---|
detections.json |
medmlx.detections.v1 candidate boxes (cccwhd, class 0 nodule) in RAS millimetres with their scores |
bundle_detections.json |
The MONAI bundle rows in patient LPS |
- Boxes map through the affine with MONAI's opposite-corner convention, so on oblique affines they differ from a box enclosing all eight corners.
runreturns{"outputs": {...}, "artifacts": {...}, "details": {...}}.artifactsmarksdetections.jsonas boxes in image world (RAS) space andbundle_detections.jsonas boxes in patient (LPS) space; run metadata is indetails.- Invalid inputs raise
InvalidInputError; missing or mismatched weights raiseAssetNotReadyError.
Python API
from pathlib import Path
from medmlx_core.runtime import import_mlx
from lung_nodule_mlx import RetinaNet, boxes_to_world, detections, predict_maps
from lung_nodule_mlx.medmlx import prepare_image
image, affine = prepare_image(Path("ct.nii.gz"))
mx = import_mlx()
network = RetinaNet(mx.load("network.safetensors"), mx=mx)
maps, padded_shape = predict_maps(image, network)
boxes, scores, labels = detections(maps, padded_shape, image.shape[2:])
world_ras = boxes_to_world(boxes, affine)
- Arrays are float32 NCDHW in MONAI's
(i, j, k)order, anddetectionsreturns voxel boxes. - Box selection uses stable NumPy top-k and needs no compiler. Tied scores keep their original order, so overlapping boxes can differ from MONAI runs when scores tie.
- Inference requires Apple Silicon with Metal.
Use with MedMLX
Use the MedMLX MCP server to run lung-nodule 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 lung-nodule.
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 lung-nodule-mlx 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lung_nodule_mlx-0.3.0.tar.gz | 30.7 kB | Without provenance | Details for lung_nodule_mlx-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lung_nodule_mlx-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for lung_nodule_mlx-0.3.0-py3-none-any.whl |
Total release size: 75.2 kB
Release files / lung_nodule_mlx-0.3.0.tar.gz
| Download URL | lung_nodule_mlx-0.3.0.tar.gz |
|---|---|
| Size | 30.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2d3b664620ce50f92ef0b36339c7cb54a450549a7ebe900051d587b97c26312
|
|
BLAKE2b-256 checksum How to use checksums |
2ea09adb9ac2d8d5ad7a65143dc9895e5ea81b0422e14ad86e356bd9c2325c5d
|
| 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 / lung_nodule_mlx-0.3.0-py3-none-any.whl
| Download URL | lung_nodule_mlx-0.3.0-py3-none-any.whl |
|---|---|
| Size | 44.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76b466c12c963aa93683bd6f3da6fbce44351e1b9b2e69df6d0a239cb0e9544f
|
|
BLAKE2b-256 checksum How to use checksums |
cacfb9a9d96b75e4993982e3051c05963fabf5fd538f3b2dcb4be1af80b404aa
|
| 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 lung-nodule-mlx 0.3.0
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.