MABERAMABERA commited on
Commit
bf15ce2
·
verified ·
1 Parent(s): 35b4a66

Release EndoMet-Net: GLENDA endometriosis vs no-pathology, ConvNeXt-T 3-fold ensemble

Browse files
README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ library_name: timm
4
+ pipeline_tag: image-classification
5
+ tags: [endomet-net, medical-imaging, endometriosis, laparoscopy, surgery, convnext, research-only]
6
+ datasets: [GLENDA]
7
+ ---
8
+
9
+ # EndoMet-Net: endometriosis vs no-pathology classifier for laparoscopic frames (GLENDA v1.0)
10
+
11
+ **Research use only. This is not a medical device and must not be used for clinical decisions.**
12
+
13
+ Given a single laparoscopic video frame, the model estimates whether visible endometriosis is present.
14
+ It is an ensemble of three ConvNeXt-Tiny models (one per cross-validation fold), initialised from
15
+ `timm/convnext_tiny.fb_in22k_ft_in1k` (ImageNet-22k pretraining) and fine-tuned on GLENDA v1.0.
16
+
17
+ - **Author:** MARTIN MAATI MABERA
18
+ - **Classes:** `no_endometriosis`, `endometriosis`
19
+ - **Input:** RGB frame resized to 384x384, ImageNet normalisation
20
+ - **Output:** probability per class (mean of the 3 fold models, each averaged with a horizontal flip)
21
+
22
+ ## Quick start
23
+ ```bash
24
+ pip install timm safetensors torch torchvision pillow
25
+ python inference.py frame.jpg
26
+ ```
27
+
28
+ ## Training data
29
+ GLENDA v1.0 (Leibetseder et al., 2020): 5,049 frames used (302 lesion sequences
30
+ labelled from expert masks, 27 no-pathology sequences; at most 40
31
+ evenly spaced frames per sequence), from an estimated 156 surgeries.
32
+
33
+ ## Evaluation protocol
34
+ - 3-fold cross-validation, stratified by class and **grouped by surgery**, so no surgery contributes frames to both
35
+ training and held-out data within a fold.
36
+ - GLENDA does not provide patient identifiers. Surgeries were approximated as groups of videos with consecutive IDs,
37
+ merged further when they shared an identical frame (perceptual hash) or a near-identical frame (cosine similarity of
38
+ ImageNet-pretrained ConvNeXt-T embeddings > 0.95).
39
+ - Metrics are frame-level unless stated; sequence-level scores average predictions over each video sequence.
40
+
41
+ ## Results (held-out surgeries, ConvNeXt-T, 3 folds)
42
+ | Metric (%) | Mean ± SD | Fold 0 | Fold 1 | Fold 2 |
43
+ |---|---|---|---|---|
44
+ | AUC | 96.1 ± 4.1 | 91.3 | 98.5 | 98.4 |
45
+ | Sensitivity | 93.5 ± 4.2 | 88.8 | 97.0 | 94.8 |
46
+ | Specificity | 89.0 ± 8.6 | 79.4 | 96.1 | 91.6 |
47
+ | Macro-F1 | 89.7 ± 6.3 | 82.4 | 94.2 | 92.3 |
48
+ | Balanced accuracy | 91.3 ± 6.4 | 84.1 | 96.5 | 93.2 |
49
+ | Accuracy | 92.5 ± 5.3 | 86.6 | 96.9 | 94.0 |
50
+ | Sequence-level macro-F1 | 84.8 ± 7.5 | 78.9 | 93.3 | 82.2 |
51
+
52
+ Each fold model is scored on its own held-out surgeries. The released ensemble averages the three fold models; its
53
+ performance on new patients is estimated by these cross-validation results and was not measured separately.
54
+
55
+ ## Disclosures and limitations
56
+ - **Near-duplicate analysis.** After grouping, we measured each held-out frame's highest similarity to any training
57
+ frame (fold 0): 0.0% of held-out frames had a training match above 0.95,
58
+ 0.4% above 0.93 and 9.2% above 0.90 (median nearest-neighbour similarity
59
+ 0.862). Visual inspection of the most similar pairs (about 0.94) suggested that a small number of
60
+ held-out frames may still depict the same surgical scene as training frames under different video IDs. A sensitivity
61
+ analysis with a stricter threshold (0.92) was not performed for this release, so the reported performance may be
62
+ slightly optimistic.
63
+ - **Model selection.** The training epoch was chosen by early stopping on each fold's held-out data, which can also
64
+ make the reported scores slightly optimistic.
65
+ - **Shortcut checks.** All frames share one resolution (640x360), and no-pathology video IDs fall within the range of
66
+ lesion video IDs (no separate recording batch).
67
+ - **Shortcut probe and Grad-CAM:** not yet performed. We have not yet verified with saliency maps that predictions rely on lesion regions rather than other scene content.
68
+ - **Small healthy class.** No-pathology frames come from about 18 surgeries, so the
69
+ specificity estimate rests on few patients.
70
+ - **Single source.** All data come from one dataset; performance on other hospitals, cameras or populations is unknown.
71
+ No external validation was performed.
72
+ - **Frame labels.** Sequence frames inherit the label of the sequence's expert-annotated keyframe; a lesion may be
73
+ partly hidden or out of view in some frames.
74
+
75
+ ## License
76
+ CC BY-NC 4.0, following the GLENDA dataset license (non-commercial use only, attribution required).
77
+ Check the license of the initial weights (`timm/convnext_tiny.fb_in22k_ft_in1k`) on its model card before reuse.
78
+
79
+ ## Citations
80
+ - A. Leibetseder, S. Kletz, K. Schoeffmann, S. Keckstein, J. Keckstein. *GLENDA: Gynecologic Laparoscopy Endometriosis
81
+ Dataset.* MultiMedia Modeling (MMM) 2020.
82
+ - Z. Liu et al. *A ConvNet for the 2020s.* CVPR 2022.
83
+ - R. Wightman. *PyTorch Image Models (timm).* https://github.com/huggingface/pytorch-image-models
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "EndoMet-Net",
3
+ "architecture": "convnext_tiny",
4
+ "initialised_from": "timm/convnext_tiny.fb_in22k_ft_in1k",
5
+ "classes": [
6
+ "no_endometriosis",
7
+ "endometriosis"
8
+ ],
9
+ "input_size": 384,
10
+ "mean": [
11
+ 0.485,
12
+ 0.456,
13
+ 0.406
14
+ ],
15
+ "std": [
16
+ 0.229,
17
+ 0.224,
18
+ 0.225
19
+ ],
20
+ "weights": [
21
+ "model_fold0.safetensors",
22
+ "model_fold1.safetensors",
23
+ "model_fold2.safetensors"
24
+ ],
25
+ "ensemble": "mean softmax over fold models and a horizontal flip"
26
+ }
inference.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ EndoMet-Net: endometriosis vs no-pathology classifier for laparoscopic frames (GLENDA v1.0).
3
+ Research use only. Not a medical device. See README.md for limitations and license.
4
+
5
+ Usage:
6
+ python inference.py path/to/frame.jpg [more frames ...]
7
+ """
8
+ import json, os, sys
9
+ import torch, timm
10
+ from PIL import Image
11
+ from safetensors.torch import load_file
12
+ from torchvision.transforms import v2 as T
13
+
14
+ HERE = os.path.dirname(os.path.abspath(__file__))
15
+ CFG = json.load(open(os.path.join(HERE, "config.json")))
16
+
17
+ def load_models(device="cpu"):
18
+ models = []
19
+ for fname in CFG["weights"]:
20
+ m = timm.create_model(CFG["architecture"], pretrained=False, num_classes=len(CFG["classes"]))
21
+ m.load_state_dict(load_file(os.path.join(HERE, fname)))
22
+ models.append(m.eval().to(device))
23
+ return models
24
+
25
+ TRANSFORM = T.Compose([
26
+ T.ToImage(),
27
+ T.Resize((CFG["input_size"], CFG["input_size"]), antialias=True),
28
+ T.ToDtype(torch.float32, scale=True),
29
+ T.Normalize(CFG["mean"], CFG["std"]),
30
+ ])
31
+
32
+ @torch.no_grad()
33
+ def predict(models, image, device="cpu"):
34
+ """Returns {class_name: probability}, averaged over the fold models and a horizontal flip."""
35
+ x = TRANSFORM(image.convert("RGB")).unsqueeze(0).to(device)
36
+ probs = 0
37
+ for m in models:
38
+ logits = (m(x) + m(torch.flip(x, dims=[3]))) / 2
39
+ probs = probs + logits.softmax(1)
40
+ probs = (probs / len(models))[0].cpu().tolist()
41
+ return dict(zip(CFG["classes"], probs))
42
+
43
+ if __name__ == "__main__":
44
+ device = "cuda" if torch.cuda.is_available() else "cpu"
45
+ models = load_models(device)
46
+ for path in sys.argv[1:]:
47
+ p = predict(models, Image.open(path), device)
48
+ label = max(p, key=p.get)
49
+ print(f"{path}: {label} (P(endometriosis) = {p['endometriosis']:.3f})")
model_fold0.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b8d85230f18ca585025f46a7fb81f39463423271b9f41b1ae42e9f123bc36b1
3
+ size 111304312
model_fold1.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c35b7034e88aa1ee0f405c0f39b1a4c86e19e6225fb435c6c2bc33937cb7cc7
3
+ size 111304312
model_fold2.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62e460421dce891b15c89d28926427e22f2a7d45758a1893300fe149215751a4
3
+ size 111304312