Skip to main content

CervicalSeg

Inference-only binary cervical lesion segmentation using DINOv3 ViT-S/16, DPT, and WTConv.

Classes are background and lesion. The model detects the lesion region only; it does not predict red, blue, or green annotation categories. This package is intended for research use and is not a clinical diagnostic device.

The package supports both DINOv3 state-dict layouts used by Transformers 4.56+ and 5.x.

Local installation

pip install -e .

The source checkout automatically finds weights/model.safetensors. After the public release, an installed wheel downloads the versioned weights from PlanetSMH/CervicalSeg automatically. A local weights file can also be selected explicitly:

from cervicalseg import CervicalSeg

segmenter = CervicalSeg(weights_path="/path/to/model.safetensors")
result = segmenter.predict("image.jpg")

result.save_mask("mask.png")
result.save_overlay("overlay.jpg")

result.mask is an H x W uint8 NumPy array restored to the original image size. Class indices are 0=background and 1=lesion. save_mask() writes a binary PNG with values 0 and 255. The single green overlay colour is visualization only and does not represent a lesion subtype.

Batch inference

results = segmenter.predict_batch(
    ["a.jpg", "b.jpg"],
    batch_size=2,
    return_probabilities=False,
)

Input may be a path, a PIL RGB image, or an H x W x 3 RGB NumPy array. Set return_probabilities=True to populate result.probabilities with a 2 x H x W float32 array. Channel 0 is background probability and channel 1 is lesion probability.

Command line

cervicalseg image1.jpg image2.jpg \
  --weights /path/to/model.safetensors \
  --output results

Hugging Face weights

Published weights are downloaded automatically and pinned to the package version:

segmenter = CervicalSeg()

# Explicit repository selection is also supported.
segmenter = CervicalSeg(repo_id="PlanetSMH/CervicalSeg", revision="v0.2.0")

Downloaded assets are cached by huggingface_hub. CERVICALSEG_WEIGHTS may be set to a local weights path for offline use.

Build the package

python -m build
python -m twine check dist/*

The Python distributions contain inference code and license notices only. Model weights are published separately on Hugging Face Hub.

Third-party notices

The trained weights contain DINOv3 materials distributed under the DINOv3 License. WTConv-derived code is used under the MIT License. Copies are provided in licenses/.

Metadata

Release files for cervicalseg 0.2.0

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

Source distribution (sdist)

Source distribution for cervicalseg 0.2.0
File Size Uploaded
cervicalseg-0.2.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cervicalseg 0.2.0
File Interpreter ABI Platform
cervicalseg-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / cervicalseg-0.2.0.tar.gz

Download URL cervicalseg-0.2.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
579ec3cc96c005aff34ac9a1d83be2e2e41385b75b14152cc525b3d6048bdb4b
BLAKE2b-256 checksum
How to use checksums
b781dc3ff8e27419d1fd9c84ddc9aaf2d31911c26e7dda084d645ff7db3c442e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / cervicalseg-0.2.0-py3-none-any.whl

Download URL cervicalseg-0.2.0-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f1663270a4d61c332a07298e873922823dfe7bde327f31041873b4df055bb5a
BLAKE2b-256 checksum
How to use checksums
41f5cc8663102abb55bb068d81be3c8963ebe21a27730476ef321f42e7b3eb76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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