bicbioseg
Prepare biomedical image datasets, train segmentation models, and predict masks with a Python API. Use one workflow to inspect data, compare models, and save results.
This library is in early development. APIs can change between releases.
Install
Use Python 3.11 or later.
pip install bicbioseg
Install optional features when you need them:
| Feature | Command |
|---|---|
| DeiT, Swin, PVTv2, DINOv3, and EfficientViT models | pip install 'bicbioseg[transformers]' |
| DICOM conversion | pip install 'bicbioseg[dicom]' |
| Albumentations transforms | pip install 'bicbioseg[albumentations]' |
TransUNet, including its ResNet-50 encoder, works with the base installation.
Follow the workflow
flowchart LR
A["Images and masks"] --> B["Inspect data"]
B --> C["Split dataset"]
C --> D["Train a model"]
D --> E["Evaluate on test data"]
D --> F["Predict new masks"]
E --> G["Review plots and reports"]
F --> G
Match each image with a mask that has the same filename stem. Use grayscale or RGB images. Use two-dimensional masks with integer labels.
raw/
images/
sample_001.png
sample_002.png
masks/
sample_001.png
sample_002.png
For binary segmentation, use 0 for background and positive values for foreground.
For multiclass segmentation, use class IDs from 0 through num_classes - 1.
See dataset preparation for grouping, patches, and color-mask conversion.
Train your first model
This example trains a binary U-Net and saves the workflow outputs in cell_experiment.
Use your own paired dataset and a folder of new images.
from bicbioseg import SegmentationExperiment, set_seed
set_seed(42)
exp = SegmentationExperiment(
images="raw/images",
masks="raw/masks",
model="unet",
loss="dice",
work_dir="cell_experiment",
image_size=(224, 224),
)
exp.qc()
exp.preview(show=True)
exp.prepare(split=(0.8, 0.1, 0.1), resize=(224, 224))
exp.train(epochs=50, batch_size=8, num_workers=0, early_stopping=True, patience=10)
exp.qc(splits=True)
exp.evaluate(checkpoint="best")
exp.predict("new_images", checkpoint="best", batch_size=8, save_overlay=True)
exp.report()
Review the quality report and preview before training.
The workflow saves split data, checkpoints, training history, predictions, evaluation scores, and a report.
Choose checkpoint="best", "final", "last", a checkpoint path, or "current" for evaluation and prediction.
Reports include the selected checkpoint, split, threshold, metrics, and example predictions.
Use the components you need
| Component | Use it to |
|---|---|
SegmentationExperiment |
Run preparation, training, evaluation, and prediction in one workspace. |
ImageOps |
Inspect datasets, convert images, process masks, and measure objects. |
Segmenter |
Train and use a model with prepared data or custom loaders. |
| Models | Choose a CNN, transformer, or hybrid encoder and a segmentation decoder. |
DataLoader and augmentation |
Create paired image/mask batches and transforms. |
| Configuration objects | Save reusable model, dataset, training, and experiment settings. |
See the component diagram and user guide.
Choose a model
The library provides 16 architectures. Each link lists its variants, defaults, input requirements, and configuration example.
| Model | Main choices |
|---|---|
| U-Net | Width, depth, and upsampling method |
| IS-Net | Full DIS segmentation network, with optional five-head deep supervision and upstream weight loading |
| CAttention U-Net | U-Net with decoder channel and spatial attention |
| DoubleUNet | VGG19, ResNet-50, or ResNet-101 first encoder. RGB binary masks only. |
| TransUNet | Custom CNN or ResNet-50, with lightweight, standard, and heavy transformer configurations |
| SegFormer | Four configurable Mix Transformer stages |
| DeiT | tiny, small, or base, with optional distilled encoder |
| Swin with convolutional decoder | tiny, small, or base |
| PVTv2 with convolutional decoder | b0 through b5 |
| Full Swin-Unet | tiny, small, or base, with configurable Swin decoder depth |
| PVTFormer | b0 through b5, with residual decoding and multiscale fusion |
| ResUNet++ | Residual blocks, attention, and configurable ASPP |
| UNeXt | base, small, or custom stage widths |
| DINOv3 with trainable decoder | small or base, optional pretrained/frozen encoder, configurable decoder widths |
| MedNeXt in 2D | small or base, configurable widths, kernels, depth, and deep supervision |
| EfficientViT segmentation | b0 through b3, with a lightweight multiscale MBConv head |
DeiT, Swin, and PVTv2 are separate architecture choices. Select them through model or architecture.
See model selection for shared behavior and setup checks.
Predict with a saved model
from bicbioseg import Segmenter
model = Segmenter.load("cell_experiment/runs/unet_dice/best_model.pt")
results = model.inference(
"new_images", save_to="predictions", batch_size=8,
save_overlay=True, structured=True,
)
print(results[0]["paths"]["mask"])
print(results[0]["metadata"]["class_map"])
See inference for single images, tiled prediction, and ensembles.
Save reusable settings
from bicbioseg import Segmenter, SegmenterConfig
print(Segmenter.model_options("segformer"))
config = SegmenterConfig(
architecture="segformer",
model_kwargs={"dims": [32, 64, 160, 256], "num_layers": [2, 2, 2, 2]},
)
config.save("model.json")
model = Segmenter.from_config(SegmenterConfig.load("model.json"))
Model options are validated before construction. JSON lists are normalized automatically. Use training configuration to save periodic recovery checkpoints.
Check labels and prepare augmentation
Color-mask conversion creates one RGB color map for the dataset and saves it as JSON. Quality checks report invalid labels, ignored pixels, and missing classes across splits. Augmentation saves paired files separately from normalization and provides previews that check mask labels.
Evaluation excludes empty class comparisons by default. Images containing only ignored labels never contribute to scores. Select per-image or dataset-wide aggregation in the evaluation guide.
Continue with your task
- Prepare and inspect data
- Train, save, and resume
- Evaluate predictions and inspect failures
- Compare experiments
- Find every configuration field
- Read acknowledgments
The project uses the MIT license.
Planned Upgrades
- SAM Inference (in 0.4.0)
- SAM Finetuning (no ETA)
Metadata
Release files for bicbioseg 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 |
|---|---|---|---|---|
| bicbioseg-0.3.0.tar.gz | 116.1 kB | With provenance | Details for bicbioseg-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bicbioseg-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for bicbioseg-0.3.0-py3-none-any.whl |
Total release size: 230.7 kB
Release files / bicbioseg-0.3.0.tar.gz
| Download URL | bicbioseg-0.3.0.tar.gz |
|---|---|
| Size | 116.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
196b7a586ea60a723be27a857ed73cd2bce216c3b85650b7d782b14f24b17370
|
|
BLAKE2b-256 checksum How to use checksums |
4ad7afd40200c6f0cc46b1a515d93d1d521aa94c35b0068d5bf8b3a58ddbf892
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / bicbioseg-0.3.0-py3-none-any.whl
| Download URL | bicbioseg-0.3.0-py3-none-any.whl |
|---|---|
| Size | 114.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15d4283f4cffcba86ead20ffeaccc3e1184cd92482dba24950a600328aa7a013
|
|
BLAKE2b-256 checksum How to use checksums |
2200a3a5ca467316ddc4c18b3a9c06754e56db838c31cf15ae66cdd0f7eaf0fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for bicbioseg 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bicbioseg-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA 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.