Commit 1951d64
authored
fix: support full-image masks in instance segmentation postprocessing (#588)
* feat: add DETRInstanceSegmentation model wrapper for full-image masks
DETR-family instance segmentation models (e.g. RF-DETR-Seg) output
full-image masks at reduced resolution (input_size/4) rather than
per-box crop masks (28x28) like Mask R-CNN.
Add DETRInstanceSegmentation class (__model__ = "DETRInstSeg") that
inherits from MaskRCNNModel and overrides postprocess() to resize
masks to original image dimensions directly, instead of the box-crop
placement logic used by MaskRCNNModel.
This follows the same pattern as SSD vs YOLO for detection -- different
architectures get different model wrappers, selected via model_type in
the exported model's rt_info.
MaskRCNNModel remains unchanged for backward compatibility.
Resolves: open-edge-platform/geti#6488
* test: add unit tests for DETRInstanceSegmentation postprocess
Tests cover:
- _full_image_mask_postprocess: resize, threshold, dtype, spatial pattern preservation
- Comparison between full-image and per-box-crop postprocessing approaches
- DETRInstanceSegmentation.postprocess: basic flow, batch dim squeezing,
confidence filtering, empty results, label increment, label names,
mask positioning (verifies masks are NOT shifted to box position),
multiple detections, class attributes, and inheritance
* refactor: extract InstanceSegmentationModel base class
Introduce InstanceSegmentationModel as the common base for both
MaskRCNNModel and DETRInstanceSegmentation. The base class contains
all shared logic: initialization, output detection, preprocessing,
box rescaling, confidence/area filtering, and NMS.
Subclasses only need to implement _postprocess_single_mask():
- MaskRCNNModel: per-box-crop postprocess (_segm_postprocess)
- DETRInstanceSegmentation: full-image resize (_full_image_mask_postprocess)
This eliminates the duplicated postprocess code and makes the hierarchy
cleanly express the architectural difference between the two approaches.
Also updates the tiler to use InstanceSegmentationModel for isinstance
checks, and adds tests verifying the new hierarchy.
* fix: resolve ruff lint errors (import sorting, unused var, naming)1 parent fce6479 commit 1951d64
5 files changed
Lines changed: 371 additions & 10 deletions
File tree
- model_api
- src/model_api
- models
- tilers
- tests/unit/models
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | | - | |
18 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
110 | 131 | | |
111 | 132 | | |
112 | 133 | | |
| |||
213 | 234 | | |
214 | 235 | | |
215 | 236 | | |
216 | | - | |
| 237 | + | |
217 | 238 | | |
218 | 239 | | |
219 | 240 | | |
| |||
226 | 247 | | |
227 | 248 | | |
228 | 249 | | |
229 | | - | |
| 250 | + | |
230 | 251 | | |
231 | 252 | | |
232 | 253 | | |
233 | 254 | | |
234 | | - | |
| 255 | + | |
235 | 256 | | |
236 | 257 | | |
237 | 258 | | |
238 | 259 | | |
239 | 260 | | |
240 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
241 | 288 | | |
242 | 289 | | |
243 | 290 | | |
| |||
286 | 333 | | |
287 | 334 | | |
288 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
289 | 342 | | |
290 | 343 | | |
291 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
0 commit comments