Arviano commited on
Commit
f3e01f4
·
1 Parent(s): 91c2ecf

Update README and add inference smoke tests

Browse files
Files changed (2) hide show
  1. README.md +33 -12
  2. tests/test_inference_smoke.py +50 -0
README.md CHANGED
@@ -1,12 +1,33 @@
1
- ---
2
- title: XDL Colitis Demo
3
- emoji: 👁
4
- colorFrom: pink
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 6.5.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # XDL Colitis Demo
2
+
3
+ Simple Gradio demo for DenseNet-based colitis image classification with optional XDL overlays.
4
+
5
+ ## Features
6
+
7
+ - Single-image classification
8
+ - Folder batch inference with configurable confidence threshold
9
+ - Final folder classification by majority vote of per-image top class
10
+ - Mean confidence for the selected final class
11
+ - GradCAM + SmoothGrad overlays for classified images
12
+
13
+ ## Run
14
+
15
+ ```bash
16
+ .venv/bin/python app.py
17
+ ```
18
+
19
+ Then open the Gradio URL in your browser.
20
+
21
+ ## Project Structure
22
+
23
+ - `app.py`: minimal launcher
24
+ - `src/ui.py`: Gradio UI only
25
+ - `src/inference.py`: model loading + inference + batch/XDL pipeline
26
+ - `src/xdl.py`: DenseNet-specific XDL helper functions
27
+ - `src/densenet.py`: model definition
28
+ - `src/preprocessing.py`: inference transform
29
+
30
+ ## Notes
31
+
32
+ - The app currently uses `models/multi_smoothing1.2_reducelr_epoch116.pth`.
33
+ - If model loading fails, the UI returns a clear error instead of silently using random weights.
tests/test_inference_smoke.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile
2
+ import unittest
3
+ from pathlib import Path
4
+
5
+ from src.inference import ClassifiedPrediction, _aggregate_classification, _iter_image_paths
6
+
7
+
8
+ class TestInferenceHelpers(unittest.TestCase):
9
+ def test_iter_image_paths_filters_and_recurses(self):
10
+ with tempfile.TemporaryDirectory() as tmp:
11
+ root = Path(tmp)
12
+ (root / "a.jpg").write_bytes(b"x")
13
+ (root / "b.txt").write_text("ignore")
14
+ nested = root / "nested"
15
+ nested.mkdir()
16
+ (nested / "c.PNG").write_bytes(b"y")
17
+
18
+ paths = _iter_image_paths(root)
19
+ names = [p.name for p in paths]
20
+
21
+ self.assertEqual(names, ["a.jpg", "c.PNG"])
22
+
23
+ def test_aggregate_classification_majority_vote(self):
24
+ classified = [
25
+ ClassifiedPrediction(path=Path("1.jpg"), pred_idx=0, confidence=0.80),
26
+ ClassifiedPrediction(path=Path("2.jpg"), pred_idx=0, confidence=0.60),
27
+ ClassifiedPrediction(path=Path("3.jpg"), pred_idx=2, confidence=0.95),
28
+ ]
29
+
30
+ label, mean_conf = _aggregate_classification(classified)
31
+
32
+ self.assertEqual(label, "uc")
33
+ self.assertAlmostEqual(mean_conf, 0.70, places=6)
34
+
35
+ def test_aggregate_classification_tie_break_by_mean_confidence(self):
36
+ classified = [
37
+ ClassifiedPrediction(path=Path("1.jpg"), pred_idx=0, confidence=0.60),
38
+ ClassifiedPrediction(path=Path("2.jpg"), pred_idx=0, confidence=0.50),
39
+ ClassifiedPrediction(path=Path("3.jpg"), pred_idx=1, confidence=0.90),
40
+ ClassifiedPrediction(path=Path("4.jpg"), pred_idx=1, confidence=0.80),
41
+ ]
42
+
43
+ label, mean_conf = _aggregate_classification(classified)
44
+
45
+ self.assertEqual(label, "infeksi")
46
+ self.assertAlmostEqual(mean_conf, 0.85, places=6)
47
+
48
+
49
+ if __name__ == "__main__":
50
+ unittest.main()