Skip to main content

flexible-unet-mlx

Segment surgical tools in RGB endoscopy frames with FlexibleUNet and native MLX.

PyPI Python License Apple Silicon Hugging Face MedMLX

Model weights · MedMLX

Input Output
RGB image Tool mask at the original size

Use with MedMLX

The MedMLX MCP server is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run flexible-unet for you.

uv tool install --python 3.13 "medmlx[segment,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 flexible-unet.

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 "flexible-unet-mlx>=0.2.6"

Run

from flexible_unet_mlx.medmlx import run

result = run(image_path="frame.jpg", output_dir="out")
print(result["outputs"]["mask"])

Omitting weights_path downloads MedMLX/flexible-unet-effnetb2-mlx into the shared MedMLX cache on first use; interrupted downloads resume and later runs work offline. With MedMLX installed, medmlx setup flexible-unet downloads it ahead of time. To use your own copy, pass a folder containing flexibleunet.safetensors as weights_path. The standalone runtime also accepts a checkpoint file. 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 RGB image Pillow can read; the bundle used JPEG
output_dir Output root, created if missing
weights_path Optional .safetensors file or a folder containing it
overwrite False by default; an existing mask is replaced only when True

This 2D model reads images, not NIfTI volumes. Following the bundle's SaveImaged layout, frame.jpg produces out/frame/frame_trans.png: an 8-bit grayscale mask at the original frame size, 255 for tools and 0 for background. run returns {"outputs": {"mask": path}, "details": {...}}, with labels, frame size, network input shape, tool counts, runtime and timings. Invalid frames raise InvalidInputError; missing or mismatched weights raise AssetNotReadyError; inference failures raise ModelExecutionError; a missing native runtime raises MissingDependencyError.

Python API

from pathlib import Path

import numpy as np
from flexible_unet_mlx import forward_patch, load_model

network = load_model(Path("flexibleunet.safetensors"))
logits = forward_patch(network, np.zeros((1, 3, 736, 480), dtype=np.float32))

forward_patch takes finite float32 (B, 3, 736, 480) frames, whose spatial axes are width and height as the bundle's reader returns them, and returns raw (B, 2, 736, 480) logits; channel 1 is the tool class. Preprocessing and postprocessing are the caller's. FlexibleUNet(weights, mx=mx) runs on MLX arrays directly. load_model checks names, shapes, dtypes and finite values, not checkpoint identity. 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 flexible-unet-mlx 0.2.6

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

Source distribution (sdist)

Source distribution for flexible-unet-mlx 0.2.6
File Size Uploaded Provenance Actions
flexible_unet_mlx-0.2.6.tar.gz 27.0 kB Without provenance Details for flexible_unet_mlx-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flexible-unet-mlx 0.2.6
File Interpreter ABI Platform Actions
flexible_unet_mlx-0.2.6-py3-none-any.whl Python 3 none any Details for flexible_unet_mlx-0.2.6-py3-none-any.whl

Total release size: 62.5 kB

Release files / flexible_unet_mlx-0.2.6.tar.gz

Download URL flexible_unet_mlx-0.2.6.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e100e0cfb1ccfa885a9be5ee42939d91b09271aebc3aee8d8314afc6f725487e
BLAKE2b-256 checksum
How to use checksums
1c29c9933326ac37cf70b79e7a2b1a26941429bbdda784715296fcf26101c3d1
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 / flexible_unet_mlx-0.2.6-py3-none-any.whl

Download URL flexible_unet_mlx-0.2.6-py3-none-any.whl
Size 35.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99e188ccc77a470f404979d4be62c8f9295f867c9d2e7ec9f4bed63896e29163
BLAKE2b-256 checksum
How to use checksums
758499ec6ed99b19a7c4d6a73b4514c524b0453cd14f87a962a0e7e0242e0889
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 flexible-unet-mlx 0.2.6

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