Skip to main content

Binary cervical lesion segmentation with DINOv3, DPT, and WTConv

Project description

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/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cervicalseg-0.2.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cervicalseg-0.2.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file cervicalseg-0.2.0.tar.gz.

File metadata

  • Download URL: cervicalseg-0.2.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cervicalseg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 579ec3cc96c005aff34ac9a1d83be2e2e41385b75b14152cc525b3d6048bdb4b
MD5 e915ef0a5cf1c9bf9d0cec139bbbaade
BLAKE2b-256 b781dc3ff8e27419d1fd9c84ddc9aaf2d31911c26e7dda084d645ff7db3c442e

See more details on using hashes here.

File details

Details for the file cervicalseg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cervicalseg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cervicalseg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f1663270a4d61c332a07298e873922823dfe7bde327f31041873b4df055bb5a
MD5 7d7fc71e80e370000a4209061cc702d8
BLAKE2b-256 41f5cc8663102abb55bb068d81be3c8963ebe21a27730476ef321f42e7b3eb76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page