DIGITAL MICROSCOPY · DEEP LEARNING

AFB detection for digital microscopy.

A YOLOv8n deep-learning model trained on labelled Ziehl–Neelsen microscopy images to locate candidate acid-fast bacilli (AFB). It supports direct image analysis and tiled inference for large images and whole-slide workflows.

FEATURES

Working with microscopy images

01

AFB detection

The model identifies candidate acid-fast bacilli and returns bounding boxes with confidence scores.

02

Large-image support

Tiled processing handles large microscopy images and whole-slide imaging workflows without loading an entire slide into memory.

03

Overlap handling

Overlapping tiles improve edge coverage, while global non-maximum suppression consolidates repeated boundary detections.

04

Image and slide inputs

Use common raster microscopy images directly or process supported slide formats with the OpenSlide workflow.

05

CLI inference

Run the supplied checkpoint from the command line with configurable confidence and image-calibration options.

06

Local web interface

A FastAPI service and browser interface support local image review and annotation workflows.

07

Python libraries

Built with PyTorch, Ultralytics YOLO, OpenCV, OpenSlide, and FastAPI for local research use.

08

Included model weights

The included best.pt checkpoint can be verified with its SHA-256 sidecar before local use.

WORKFLOW

From microscopy image to candidate detections.

Overlapping tiles help cover objects near tile edges. The detector compares boxes across tiles to remove repeated detections.

  1. 01
    Choose an image or slide

    Provide a raster Ziehl–Neelsen microscopy image or a supported whole-slide image.

  2. 02
    Tile when needed

    Large images are divided into overlapping tiles to preserve detail and control memory use.

  3. 03
    Run YOLOv8n inference

    The single-class detector predicts candidate AFB bounding boxes and confidence scores.

  4. 04
    Consolidate detections

    Global non-maximum suppression removes duplicate predictions from overlapping tiles.

  5. 05
    Review locally

    Inspect the image, locations, and confidence outputs in the CLI or local web interface.

THE MODEL

A single-class YOLOv8n detector trained for AFB localisation.

The released model is a deep-learning object detector trained for 150 epochs on labelled Ziehl–Neelsen microscopy imagery. It predicts the location of visual AFB candidates; each prediction includes a bounding box and confidence score.

Model specification
ItemDescription
ArchitectureUltralytics YOLOv8n
TaskSingle-class object detection
Target classCandidate acid-fast bacillus (AFB)
Training duration150 epochs
Model artifact03_MODELS/best.pt

RECORDED DEVELOPMENT OUTPUTS

Precision
0.7186
Recall
0.5620
mAP@50
0.6406
mAP@50–95
0.3119
Training history showing losses and model-development metrics across 150 epochs
Training curves from the 150-epoch development run.

ARCHITECTURE

Processing steps

  1. InputZN microscopy image / WSI
  2. ImagingOpenCV / OpenSlide
  3. DetectionPyTorch + YOLOv8n
  4. Post-processingTiling + global NMS
  5. OutputBoxes + confidence scores
  6. AccessCLI / FastAPI / Web UI

QUICK START

Run the model on your own image.

Install the project requirements, then pass the included checkpoint and a local microscopy image to the inference command.

git clone https://github.com/abusuraihsakhri/pretrained-tb-afb-detection-model.git
cd pretrained-tb-afb-detection-model
python -m pip install -r requirements.txt

python 02_CODE/scripts/04_inference.py --model 03_MODELS/best.pt --wsi path/to/microscopy-image.png --conf 0.25
Read the full setup guide →

LIMITATIONS

Important boundaries for using the model.

OPEN SOURCE

Code and model weights

The repository includes the model artifact, inference scripts, large-image processing, a local API, and a browser-based review interface. The README includes commands for running the model and opening the local review interface. To annotate microscopy images or train your own detector, visit the TB AFB Detection Toolkit.