Downloads · 30 days
20
8% of all-time downloads
lab225/cxr-sextants
cxr-sextants is a image classification model from lab225. Use it when you need a label for an image. It is set up for keras. The card lists the license as apache-2.0.
CXR Sextants is a decision-support module that performs binary (yes/no) classification of three types of pulmonary lesions — cavities, infiltrates (increased parenchymal density), and nodules — in each of the six anat…
Downloads · 30 days
20
8% of all-time downloads
All-time downloads
265
Public
Repo size
754 MB
Likes
1
Public
Click a slice to open those files.
.keras752 MB · 100%
From the Hugging Face model README
CXR Sextants is a decision-support module that performs binary (yes/no) classification of three types of pulmonary lesions — cavities, infiltrates (increased parenchymal density), and nodules — in each of the six anatomical zones ("sextants") of the lungs.
It is a component of a larger Flask-based AI-services web platform and is exposed through a standardized REST API.
⚠️ Research use only. This system is not intended to replace a radiologist and is not approved for clinical diagnosis. It is a decision-support tool that draws attention to suspicious areas and provides structured preliminary information.
Chest radiography remains one of the most widely used diagnostic procedures, particularly in regions with a high prevalence of tuberculosis. Its interpretation, however, requires considerable experience and is known to be affected by observer fatigue and inter-reader variability. CXR Sextants provides automated preliminary analysis to support that workflow.
The lung fields are divided into six anatomical zones (three per lung: upper, middle, lower), a scheme traditional for radiological reporting of tuberculosis and other diffuse lung diseases. For each combination of zone and lesion type, the system produces a probability estimate, which can be used both for case prioritization and for generating a structured preliminary report.
Three separate Keras models are used, one per finding type:
| Model | Finding | Radiological definition |
|---|---|---|
cavs | Cavities | Air-containing spaces with a definable wall within the lung parenchyma. Characteristic of tuberculosis and some fungal infections, as well as abscesses and cavitating neoplasms. |
dens | Infiltrates | Areas of increased parenchymal density, corresponding to increased attenuation due to consolidation or infiltration. Observed in pneumonia, tuberculosis with an exudative component, and other inflammatory processes. |
nods | Nodules | Rounded focal opacities not exceeding 3 cm in diameter. May represent early malignancy, granulomas, or metastatic lesions. |
Each model outputs a probability in [0, 1]. A threshold of 0.5 converts it to a binary label (below → negative, above → positive). Both the probability and the binary label are stored in the output JSON.
| Right lung | Left lung |
|---|---|
R1 — upper | L1 — upper |
R2 — middle | L2 — middle |
R3 — lower | L3 — lower |
Nominal anatomical levels: the upper zone is superior to the anterior second rib, the middle zone lies between the second and fourth ribs, and the lower zone is inferior to the fourth rib.
Intended: research; retrospective analysis; case prioritization and triage support; generation of structured preliminary reports; a baseline for further methodological work on zone-based CXR classification.
Out of scope: primary or autonomous clinical diagnosis; use on pediatric radiographs (unless separately validated); use on modalities other than posteroanterior/anteroposterior chest radiographs; any use where a failure to detect a lesion could directly harm a patient without radiologist oversight.
The system accepts chest radiographs in DICOM or NIfTI format (.nii / .nii.gz), the standard
container in medical image processing pipelines.
A pre-computed binary lung mask in NIfTI format with the same spatial dimensions is
required. It is produced by a separate segmentation component of the platform and is stored
alongside the input with the suffix -cxr_lungs.nii.gz. The mask is used to define the
bounding box for zone cutting, to restrict analysis to lung tissue, and to build the visual
overlay.
Preprocessing steps:
Zone boundaries are not derived from explicit rib detection. Instead, the SextantCutter
component computes the bounding box of the combined lung mask (with a 3% margin) and finds two
cut positions along the appropriate axis that divide the masked area into three parts of equal
pixel count. This is more robust than anatomical landmark detection and yields reasonable
boundaries even when lung position or shape is unusual. The right and left lungs are separated
at the column midpoint of the bounding box, corresponding to the mediastinum.
Single-lung cases (e.g., after pneumonectomy, or a severely tilted image) are detected
automatically from the distribution of the lung mask across the left and right halves. In such
cases the visible lung is divided into three zones and predictions are emitted for the three
applicable codes (R1/R2/R3 or L1/L2/L3).
Note on coordinates. Zone cutting operates in the coordinate system of the original NIfTI file, where the axes may not correspond to those of the display image: the flip and transpose applied for preview generation turn the left–right NIfTI axis into the row axis of the display image, and vice versa. Boundaries computed in NIfTI space must therefore be remapped to display space when drawing the overlay.
A fixed structure with predictions for all six zones (R1, R2, R3, L1, L2, L3), each
containing three sub-dictionaries for the three model types, plus fields for the detected lung
side and the processing status (so that downstream components can handle edge cases such as
single-lung images).
{
"R1": {
"cavs": {"probability": 0.07, "class": 0},
"dens": {"probability": 0.81, "class": 1},
"nods": {"probability": 0.22, "class": 0}
},
"R2": { "...": "..." },
"lung_side": "both",
"status": "ok"
}
A semi-transparent colored layer is painted over each zone according to its severity score, defined as the maximum probability across the three classifiers. Maximum (rather than sum or average) is used because a zone is clinically of interest if any of the three lesion types shows an elevated probability; this avoids artificially inflating scores in zones with multiple moderate findings while preserving sensitivity to any single strong signal.
The color mapping follows a spectral ramp from blue (severity near 0) through cyan, green, yellow, and orange to red (severity near 1), blended at 45% opacity so the underlying anatomy stays visible. Each zone carries a small text label with the zone code and severity percentage, rendered with a dark outline for readability against light and dark backgrounds.
A structured text report lists each zone with a positive classifier result, provides the full radiological definition of the detected finding, and appends a brief glossary of zone boundaries. Reports are available in English and Russian. Report generation is implemented as a separate module that reads the output JSON and applies formatting templates, so the format or language set can be changed without touching the classification logic.
import keras
cavs = keras.saving.load_model("models/cavs.keras") # cavities
dens = keras.saving.load_model("models/dens.keras") # infiltrates
nods = keras.saving.load_model("models/nods.keras") # nodules
# zone_patch: preprocessed sextant patch, shape (1, H, W, C)
p_cav = float(cavs.predict(zone_patch)[0][0])
label = int(p_cav > 0.5)
Downloading the weights directly from the Hub:
from huggingface_hub import hf_hub_download
path = hf_hub_download(repo_id="lab225/cxr-sextants", filename="models/cavs.keras")
For the full pipeline (NIfTI ingestion → segmentation → zone cutting → classification → JSON → overlay → report), see the accompanying code repository and Space linked below.
TODO
Status: evaluation of the three released Keras classifiers is not yet complete. The figures below come from YOLOv8-based experiments conducted within the same research programme. Unless the released weights are exports of these same experiments, they must not be read as the performance of the
cavs/dens/nodsmodels in this repository.
| Setting | Architecture | Task granularity | AUC | Accuracy |
|---|---|---|---|---|
| Cavities, whole lungs | YOLOv8 | Whole-image (both lungs) | 0.95 | 88% |
| Cavities, lung sextants | YOLOv8 | Per-zone (sextant) | 0.89 | 76.9% |
The drop from whole-image to per-zone operation (AUC 0.95 → 0.89) is expected: each zone classifier sees only one sixth of the lung field, has far less anatomical context, and lesions lying near a zone boundary may be truncated across two patches.
Negative-class provenance. In the sextant experiment, approximately 40% of the healthy (negative) sextants were drawn from external datasets rather than from the same cohort as the positive examples. This is a material caveat: when negatives and positives originate from different acquisition sources, a classifier can achieve high apparent discrimination by learning source-specific characteristics — detector type, exposure, post-processing, digitization artifacts — instead of the pathology itself. The reported AUC should therefore be regarded as an upper bound until validated on negatives drawn from the same distribution as the positives.
<!-- TODO before publication: - Report n (test), positive rate, and the operating threshold used for the accuracy figure. - Add 95% CIs. An AUC of 0.89 alongside 76.9% accuracy suggests the threshold is not optimal for the class balance; state whether 0.5 or a tuned threshold was used. - Run an ablation with same-source negatives only, and/or a source-classification probe, to quantify how much of the AUC is attributable to dataset provenance rather than to cavities. - Confirm the train/test split was performed at the patient level to prevent leakage. -->Pending.
| Lesion | Zones | Accuracy | Sensitivity | Specificity | ROC-AUC | n (test) | Positive rate |
|---|---|---|---|---|---|---|---|
Cavities (cavs) | all | TODO | TODO | TODO | TODO | TODO | TODO |
Infiltrates (dens) | all | TODO | TODO | TODO | TODO | TODO | TODO |
Nodules (nods) | all | TODO | TODO | TODO | TODO | TODO | TODO |
Operating threshold: 0.5 (uniform across zones and lesion types; per-zone calibration is identified as future work).
<!-- TODO: if a radiologist reader study was performed, summarize agreement statistics here. -->The system is a decision-support tool operating in a high-stakes clinical domain. False negatives may delay diagnosis of tuberculosis or malignancy; false positives may trigger unnecessary follow-up imaging and radiation exposure. Outputs must always be reviewed by a qualified radiologist. Model performance may vary across demographic subgroups; subgroup analysis has not yet been performed. No patient-identifiable data is contained in this repository.
The module is registered as a worker class within the AI-services platform, inheriting from a common base and implementing a standardized processing interface, so that applications can be added or processing backends replaced without changing infrastructure code.
Pipeline stages for a single case: file upload and registration → data preparation (conversion to internal format) → lung field segmentation via a pre-trained mask model → zone-based classification with the three classifiers → structured JSON output → creation of preview images for the web interface. Stages are orchestrated by a worker manager maintaining a task queue; each stage is a separate method, so a failed stage can be restarted without repeating the whole pipeline. Status and error messages are written to a per-case log retrievable through the API.
The REST API covers the full lifecycle of a case: uploading files (directly or by URL), starting the analysis, checking processing status, retrieving results and preview images, and removing cases. Authentication is handled externally through the Ory Kratos identity management system; the application itself does not manage user credentials.
The code and the model weights in this repository are released under the
Apache License, Version 2.0. A copy of the license is available in the
LICENSE file and at
https://www.apache.org/licenses/LICENSE-2.0.
Copyright 2026 NIH/NIAID, UIIP NASB
Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Apache-2.0 governs this software and these weights only. It does not grant any rights to the clinical data used for training, which remains subject to its own data use agreement. Users who publish work derived from this model are asked to acknowledge the data source in accordance with the applicable citation guidelines.
Nothing in this license authorizes clinical use. This model is provided for research purposes only, is not a certified medical device, and must not be used for primary or autonomous diagnosis.
Developed under ISTC Project No. PR150.