multimodalart HF Staff commited on
Commit
69b9299
·
verified ·
1 Parent(s): 9d8b828

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ examples/real_colon_004-001_frame13.jpg filter=lfs diff=lfs merge=lfs -text
37
+ examples/real_colon_004-001_frame25.jpg filter=lfs diff=lfs merge=lfs -text
38
+ examples/real_colon_004-001_frame37.jpg filter=lfs diff=lfs merge=lfs -text
39
+ examples/real_colon_004-001_frame49.jpg filter=lfs diff=lfs merge=lfs -text
40
+ examples/real_colon_004-001_frame61.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,51 @@
1
  ---
2
- title: True Colon Polyp Detection
3
- emoji:
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.24.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: TRUE-Colon Polyp Detection
3
+ emoji: 🩺
4
+ colorFrom: purple
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 6.24.0
 
8
  app_file: app.py
9
+ short_description: RT-DETR polyp detector on REAL-Colon colonoscopy frames
10
+ python_version: "3.12"
11
+ startup_duration_timeout: 30m
12
  ---
13
 
14
+ # TRUE-Colon: Real-Time Polyp Detection
15
+
16
+ Interactive demo of the **RT-DETR** detector from the paper *TRUE-Colon: Exposing a
17
+ Consistent Transfer Asymmetry in Real-Time Polyp Detection* (MICCAI 2026 EndoLINA
18
+ Workshop). The model was trained on **REAL-Colon** — 60 complete, unedited colonoscopy
19
+ procedures — and detects polyps (lesions) in individual colonoscopy frames.
20
+
21
+ ## Usage
22
+
23
+ Upload a colonoscopy frame, adjust the confidence and IoU thresholds, and click
24
+ **Detect Polyps**. The model draws green bounding boxes around detected lesions with
25
+ confidence scores.
26
+
27
+ > ⚠️ **Research demo only — NOT for clinical use.** The model has not been validated
28
+ > prospectively or cleared by any regulator.
29
+
30
+ ## Model
31
+
32
+ - **Checkpoint**: [`sdoerrich97/true_colon_rtdetr_realcolon_s0`](https://huggingface.co/sdoerrich97/true_colon_rtdetr_realcolon_s0)
33
+ - **Architecture**: RT-DETR (via Ultralytics)
34
+ - **Input**: 640 × 640
35
+ - **Classes**: 1 (`lesion`)
36
+ - **License**: AGPL-3.0 (inherited from Ultralytics training)
37
+
38
+ ## Example images
39
+
40
+ Examples are from the [REAL-Colon](https://doi.org/10.1038/s41597-024-03359-0) dataset
41
+ (Biffi et al., *Scientific Data* 2024, CC BY 4.0) and [CVC-ClinicDB](https://polyp.grand-challenge.org/CVCClinicDB/) (CC BY 4.0).
42
+
43
+ ## Citation
44
+
45
+ ```bibtex
46
+ @article{doerrich2026truecolon,
47
+ title={TRUE-Colon: Exposing a Consistent Transfer Asymmetry in Real-Time Polyp Detection},
48
+ author={Sebastian Doerrich and Andreas Franz Schwab and Francesco {Di Salvo} and Shyam Nandan Rai and Hanh Huyen My Nguyen and Christian Ledig},
49
+ year={2026}, eprint={2608.13711}, archivePrefix={arXiv}, primaryClass={eess.IV}
50
+ }
51
+ ```
app.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """TRUE-Colon: Real-Time Polyp Detection demo.
2
+
3
+ Loads the RT-DETR checkpoint from the TRUE-Colon paper (MICCAI 2026 EndoLINA Workshop)
4
+ and runs inference on colonoscopy frames, drawing bounding boxes around detected polyps.
5
+
6
+ Research demo only — NOT for clinical use.
7
+ """
8
+
9
+ import spaces # MUST be first
10
+ import os
11
+ import cv2
12
+ import numpy as np
13
+ import torch
14
+ from huggingface_hub import hf_hub_download
15
+ from ultralytics import YOLO
16
+ import gradio as gr
17
+
18
+ MODEL_ID = "sdoerrich97/true_colon_rtdetr_realcolon_s0"
19
+ CLASS_NAME = "lesion"
20
+ # Green-ish box color (BGR for cv2)
21
+ BOX_COLOR = (0, 255, 0)
22
+
23
+ # Download and load model at module scope
24
+ _weights_path = hf_hub_download(MODEL_ID, "model.pt")
25
+ model = YOLO(_weights_path)
26
+
27
+
28
+ def draw_detections(image: np.ndarray, results, conf_threshold: float) -> np.ndarray:
29
+ """Draw bounding boxes on the image from Ultralytics results.
30
+
31
+ Args:
32
+ image: Input image as numpy array (RGB).
33
+ results: Ultralytics prediction results.
34
+ conf_threshold: Confidence threshold for display.
35
+
36
+ Returns:
37
+ Annotated image as numpy array (RGB).
38
+ """
39
+ annotated = image.copy()
40
+ h, w = annotated.shape[:2]
41
+
42
+ for result in results:
43
+ boxes = result.boxes
44
+ for box in boxes:
45
+ conf = float(box.conf[0])
46
+ if conf < conf_threshold:
47
+ continue
48
+ cls = int(box.cls[0])
49
+ x1, y1, x2, y2 = box.xyxy[0].cpu().numpy()
50
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
51
+
52
+ # Draw box
53
+ cv2.rectangle(annotated, (x1, y1), (x2, y2), BOX_COLOR, 3)
54
+
55
+ # Draw label background
56
+ label = f"{CLASS_NAME} {conf:.2f}"
57
+ (label_w, label_h), _ = cv2.getTextSize(
58
+ label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2
59
+ )
60
+ cv2.rectangle(
61
+ annotated,
62
+ (x1, y1 - label_h - 10),
63
+ (x1 + label_w, y1),
64
+ BOX_COLOR,
65
+ -1,
66
+ )
67
+ cv2.putText(
68
+ annotated,
69
+ label,
70
+ (x1, y1 - 5),
71
+ cv2.FONT_HERSHEY_SIMPLEX,
72
+ 0.7,
73
+ (0, 0, 0),
74
+ 2,
75
+ cv2.LINE_AA,
76
+ )
77
+
78
+ return annotated
79
+
80
+
81
+ @spaces.GPU(duration=30)
82
+ def detect(
83
+ image: np.ndarray,
84
+ conf_threshold: float = 0.30,
85
+ iou_threshold: float = 0.50,
86
+ ) -> np.ndarray:
87
+ """Detect polyps in a colonoscopy frame.
88
+
89
+ Runs the TRUE-Colon RT-DETR detector on the input image and returns an
90
+ annotated copy with bounding boxes around detected lesions.
91
+
92
+ Args:
93
+ image: Colonoscopy frame as an image.
94
+ conf_threshold: Minimum detection confidence to display.
95
+ iou_threshold: NMS IoU threshold.
96
+
97
+ Returns:
98
+ Annotated image with detection boxes drawn.
99
+ """
100
+ if image is None:
101
+ return None
102
+
103
+ # Ultralytics expects RGB; Gradio passes RGB
104
+ results = model.predict(
105
+ source=image,
106
+ conf=conf_threshold,
107
+ iou=iou_threshold,
108
+ imgsz=640,
109
+ verbose=False,
110
+ )
111
+
112
+ annotated = draw_detections(image, results, conf_threshold)
113
+ return annotated
114
+
115
+
116
+ CSS = """
117
+ #col-container { max-width: 1100px; margin: 0 auto; }
118
+ .dark .gradio-container { color: var(--body-text-color); }
119
+ """
120
+
121
+ EXAMPLES = [
122
+ ["examples/real_colon_004-001_frame13.jpg"],
123
+ ["examples/real_colon_004-001_frame25.jpg"],
124
+ ["examples/real_colon_004-001_frame37.jpg"],
125
+ ["examples/real_colon_004-001_frame49.jpg"],
126
+ ["examples/cvc_2.png"],
127
+ ["examples/cvc_100.png"],
128
+ ]
129
+
130
+ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
131
+ with gr.Column(elem_id="col-container"):
132
+ gr.Markdown(
133
+ """
134
+ # 🩺 TRUE-Colon: Real-Time Polyp Detection
135
+ **RT-DETR** trained on REAL-Colon (60 full colonoscopy procedures) for polyp detection.
136
+ From the paper *TRUE-Colon: Exposing a Consistent Transfer Asymmetry in Real-Time Polyp Detection* (MICCAI 2026 EndoLINA).
137
+
138
+ [📄 Paper](https://arxiv.org/abs/2608.13711) | [🐍 Code](https://github.com/sdoerrich97/true-colon) | [⚖️ Weights](https://huggingface.co/sdoerrich97/true_colon_rtdetr_realcolon_s0)
139
+
140
+ > ⚠️ **Research demo only — NOT for clinical use.** The model has not been validated prospectively or cleared by any regulator.
141
+ """
142
+ )
143
+
144
+ with gr.Row():
145
+ with gr.Column(scale=1):
146
+ input_image = gr.Image(
147
+ label="Colonoscopy Frame",
148
+ type="numpy",
149
+ sources=["upload", "clipboard"],
150
+ )
151
+ conf_slider = gr.Slider(
152
+ label="Confidence Threshold",
153
+ minimum=0.05,
154
+ maximum=0.95,
155
+ step=0.05,
156
+ value=0.30,
157
+ )
158
+ iou_slider = gr.Slider(
159
+ label="NMS IoU Threshold",
160
+ minimum=0.10,
161
+ maximum=0.95,
162
+ step=0.05,
163
+ value=0.50,
164
+ )
165
+ run_btn = gr.Button("Detect Polyps", variant="primary")
166
+
167
+ with gr.Column(scale=1):
168
+ output_image = gr.Image(
169
+ label="Detection Result",
170
+ type="numpy",
171
+ )
172
+
173
+ run_btn.click(
174
+ fn=detect,
175
+ inputs=[input_image, conf_slider, iou_slider],
176
+ outputs=[output_image],
177
+ api_name="detect",
178
+ )
179
+
180
+ gr.Examples(
181
+ examples=EXAMPLES,
182
+ inputs=[input_image],
183
+ outputs=[output_image],
184
+ fn=detect,
185
+ cache_examples=True,
186
+ cache_mode="lazy",
187
+ )
188
+
189
+ gr.Markdown(
190
+ """
191
+ ### Example image sources
192
+ Examples from the [REAL-Colon](https://doi.org/10.1038/s41597-024-03359-0) dataset (Biffi et al., *Scientific Data* 2024, CC BY 4.0) and [CVC-ClinicDB](https://polyp.grand-challenge.org/CVCClinicDB/) (CC BY 4.0).
193
+
194
+ ### Citation
195
+ ```bibtex
196
+ @article{doerrich2026truecolon,
197
+ title={TRUE-Colon: Exposing a Consistent Transfer Asymmetry in Real-Time Polyp Detection},
198
+ author={Sebastian Doerrich and Andreas Franz Schwab and Francesco {Di Salvo} and Shyam Nandan Rai and Hanh Huyen My Nguyen and Christian Ledig},
199
+ year={2026}, eprint={2608.13711}, archivePrefix={arXiv}, primaryClass={eess.IV}
200
+ }
201
+ ```
202
+ """
203
+ )
204
+
205
+ demo.launch(mcp_server=True)
examples/cvc_100.png ADDED
examples/cvc_2.png ADDED
examples/real_colon_004-001_frame13.jpg ADDED

Git LFS Details

  • SHA256: 718322e44bc7bb7a2728c91d8b6fae84c8aa75947e99ff906efcacee33dff650
  • Pointer size: 131 Bytes
  • Size of remote file: 242 kB
examples/real_colon_004-001_frame25.jpg ADDED

Git LFS Details

  • SHA256: d76d67f52bc4f5100c49b15e5539753935b9f1a58dff0cc389a08dc31d839f65
  • Pointer size: 131 Bytes
  • Size of remote file: 248 kB
examples/real_colon_004-001_frame37.jpg ADDED

Git LFS Details

  • SHA256: 61cb4b59da9c9ef747ee693cd5bff25244aa4a9ad79ff0da6c0854f1f276de14
  • Pointer size: 131 Bytes
  • Size of remote file: 250 kB
examples/real_colon_004-001_frame49.jpg ADDED

Git LFS Details

  • SHA256: 3dbdeaf172293ccdad6912f7c1e32c93ace2f8799ce916ee42093e64b1a138dd
  • Pointer size: 131 Bytes
  • Size of remote file: 235 kB
examples/real_colon_004-001_frame61.jpg ADDED

Git LFS Details

  • SHA256: 2da54a251d305cf6c417e017548f9aa80241bf3436ca9dda8a685288aaa8cef9
  • Pointer size: 131 Bytes
  • Size of remote file: 241 kB
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ultralytics>=8.3.223
2
+ opencv-python-headless
3
+ numpy