LiteMedSAM segmentation training and inference tools.
Project description
medsam-lite-tools
medsam-lite-tools is a LiteMedSAM segmentation package for model building, fine-tuning, inference, and Python-based experimentation.
It provides:
- a LiteMedSAM model builder with pretrained initialization
- a command-line training loop for preprocessed
.npzsegmentation data - a command-line inference runner for
.npzimage samples - Python APIs for training and prediction workflows
Install
pip install medsam-lite-tools
For training workflows with common medical-image utilities:
pip install "medsam-lite-tools[train]"
Build a Model
from medsam_lite_tools import model
net = model(pretrained=True, root="./temp/")
pretrained=True builds the LiteMedSAM architecture with pretrained initialization and is the default starting point for fine-tuning. Use pretrained=False when training from scratch.
from medsam_lite_tools import model
net = model(pretrained=False)
Training
Training input is a directory of .npz files.
Each file should include:
image,img,data, orx: image arraymask,label,seg,gt, ory: binary mask array- optional
boxorbbox:[x_min, y_min, x_max, y_max]
If no box is provided, the trainer computes one from the mask.
medsam-lite-train ^
--data-dir .\train_npz ^
--output-dir .\runs\medsam_lite ^
--epochs 5 ^
--batch-size 2 ^
--lr 1e-5 ^
--checkpoint-root .\temp
The command starts from the pretrained LiteMedSAM initialization by default and writes latest.pt to the output directory.
The same workflow can be called from Python:
from medsam_lite_tools import fit
net, history = fit(
data_dir="./train_npz",
output_dir="./runs/medsam_lite",
epochs=5,
batch_size=2,
lr=1e-5,
checkpoint_root="./temp",
)
Inference
Inference input is a directory of .npz image samples. Each file should include image, img, data, or x. If box or bbox is present, it is used as the prompt box. Otherwise, the full 256 x 256 image area is used.
medsam-lite-infer ^
--input-dir .\test_npz ^
--output-dir .\runs\medsam_lite_predictions ^
--checkpoint .\runs\medsam_lite\latest.pt ^
--root .\temp
The command writes one compressed .npz mask file per input sample.
Python usage:
from medsam_lite_tools import model, predict_npz_dir
net = model(pretrained=True, root="./temp/")
outputs = predict_npz_dir(
input_dir="./test_npz",
output_dir="./runs/medsam_lite_predictions",
checkpoint="./runs/medsam_lite/latest.pt",
root="./temp",
)
print(outputs)
Notes
- The training and inference APIs use LiteMedSAM pretrained initialization when
pretrained=True.
Attribution
The model architecture and initialization workflow are based on the LiteMedSAM branch of bowang-lab/MedSAM.
- Upstream repository: https://github.com/bowang-lab/MedSAM/tree/LiteMedSAM
- Upstream license: Apache License 2.0
The vendored code is limited to the LiteMedSAM model construction path needed for training and inference experiments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medsam_lite_tools-0.1.1.tar.gz.
File metadata
- Download URL: medsam_lite_tools-0.1.1.tar.gz
- Upload date:
- Size: 36.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71fa35281d6dfb9cb5b70d9a894446d692d7352be57388a94d02247c53e06564
|
|
| MD5 |
11b46d6c6aad6462db0cd30c2aca25e5
|
|
| BLAKE2b-256 |
1254c84596574cbf764643c466402da64e451395f1f0685825ac98545b014dea
|
File details
Details for the file medsam_lite_tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: medsam_lite_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 36.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc3e5c28e82d125ca27daf0d6be9381424fdc360893e1a3fea466b68c025180
|
|
| MD5 |
1e1e83d00145e49acf681182cb87b0d5
|
|
| BLAKE2b-256 |
42a47e70887e0a165574db3bfc79e507c77906d4bad9f38e4e7d36fdc5b33cb1
|