fiducio 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. fiducio-0.1.0/.python-version +1 -0
  2. fiducio-0.1.0/CHANGELOG.md +61 -0
  3. fiducio-0.1.0/CITATION.cff +51 -0
  4. fiducio-0.1.0/LICENSE +201 -0
  5. fiducio-0.1.0/MANIFEST.in +6 -0
  6. fiducio-0.1.0/PKG-INFO +268 -0
  7. fiducio-0.1.0/README.md +222 -0
  8. fiducio-0.1.0/docs/api/calibrators.md +41 -0
  9. fiducio-0.1.0/docs/api/metrics.md +24 -0
  10. fiducio-0.1.0/docs/api/persistence.md +17 -0
  11. fiducio-0.1.0/docs/api/plots.md +6 -0
  12. fiducio-0.1.0/docs/calibrators.md +103 -0
  13. fiducio-0.1.0/docs/concepts.md +177 -0
  14. fiducio-0.1.0/docs/examples.md +65 -0
  15. fiducio-0.1.0/docs/index.md +60 -0
  16. fiducio-0.1.0/docs/installation.md +77 -0
  17. fiducio-0.1.0/docs/plots.md +56 -0
  18. fiducio-0.1.0/docs/quickstart.md +79 -0
  19. fiducio-0.1.0/examples/basic_segmentation_calibration.py +79 -0
  20. fiducio-0.1.0/examples/ensemble_pooling.py +30 -0
  21. fiducio-0.1.0/examples/pytorch_model_calibration.py +94 -0
  22. fiducio-0.1.0/examples/readme_figure.py +53 -0
  23. fiducio-0.1.0/examples/reliability_diagram.py +54 -0
  24. fiducio-0.1.0/mkdocs.yml +79 -0
  25. fiducio-0.1.0/pyproject.toml +127 -0
  26. fiducio-0.1.0/reproducibility/README.md +98 -0
  27. fiducio-0.1.0/reproducibility/generate_reference.py +134 -0
  28. fiducio-0.1.0/setup.cfg +4 -0
  29. fiducio-0.1.0/src/fiducio/__init__.py +99 -0
  30. fiducio-0.1.0/src/fiducio/base.py +374 -0
  31. fiducio-0.1.0/src/fiducio/calibrators/__init__.py +60 -0
  32. fiducio-0.1.0/src/fiducio/calibrators/_affine.py +159 -0
  33. fiducio-0.1.0/src/fiducio/calibrators/_optim.py +129 -0
  34. fiducio-0.1.0/src/fiducio/calibrators/class_conditional.py +414 -0
  35. fiducio-0.1.0/src/fiducio/calibrators/dirichlet.py +45 -0
  36. fiducio-0.1.0/src/fiducio/calibrators/ensemble_temperature.py +182 -0
  37. fiducio-0.1.0/src/fiducio/calibrators/matrix.py +62 -0
  38. fiducio-0.1.0/src/fiducio/calibrators/temperature.py +118 -0
  39. fiducio-0.1.0/src/fiducio/calibrators/vector.py +43 -0
  40. fiducio-0.1.0/src/fiducio/metrics/__init__.py +21 -0
  41. fiducio-0.1.0/src/fiducio/metrics/calibration.py +183 -0
  42. fiducio-0.1.0/src/fiducio/persistence.py +150 -0
  43. fiducio-0.1.0/src/fiducio/plots/__init__.py +121 -0
  44. fiducio-0.1.0/src/fiducio/py.typed +0 -0
  45. fiducio-0.1.0/src/fiducio/registry.py +54 -0
  46. fiducio-0.1.0/src/fiducio/utils/__init__.py +33 -0
  47. fiducio-0.1.0/src/fiducio/utils/logging.py +27 -0
  48. fiducio-0.1.0/src/fiducio/utils/stopping.py +66 -0
  49. fiducio-0.1.0/src/fiducio/utils/tensors.py +231 -0
  50. fiducio-0.1.0/src/fiducio.egg-info/PKG-INFO +268 -0
  51. fiducio-0.1.0/src/fiducio.egg-info/SOURCES.txt +68 -0
  52. fiducio-0.1.0/src/fiducio.egg-info/dependency_links.txt +1 -0
  53. fiducio-0.1.0/src/fiducio.egg-info/requires.txt +23 -0
  54. fiducio-0.1.0/src/fiducio.egg-info/top_level.txt +1 -0
  55. fiducio-0.1.0/tests/conftest.py +51 -0
  56. fiducio-0.1.0/tests/fixtures/research_reference.json +6201 -0
  57. fiducio-0.1.0/tests/test_api_extras.py +104 -0
  58. fiducio-0.1.0/tests/test_calibrators.py +184 -0
  59. fiducio-0.1.0/tests/test_class_conditional.py +46 -0
  60. fiducio-0.1.0/tests/test_cuda.py +36 -0
  61. fiducio-0.1.0/tests/test_early_stopping.py +253 -0
  62. fiducio-0.1.0/tests/test_invariants.py +103 -0
  63. fiducio-0.1.0/tests/test_metrics.py +93 -0
  64. fiducio-0.1.0/tests/test_minimal_import.py +64 -0
  65. fiducio-0.1.0/tests/test_optimizer.py +70 -0
  66. fiducio-0.1.0/tests/test_persistence.py +80 -0
  67. fiducio-0.1.0/tests/test_plots.py +67 -0
  68. fiducio-0.1.0/tests/test_research_reference.py +105 -0
  69. fiducio-0.1.0/tests/test_validation.py +96 -0
  70. fiducio-0.1.0/uv.lock +2798 -0
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-09-21
11
+
12
+ First public beta release. It accompanies the paper *Rethinking Post-Hoc
13
+ Calibration in Semantic Segmentation* (Transactions on Machine Learning Research).
14
+
15
+ ### Added
16
+
17
+ - Model-agnostic `Calibrator` API with a consistent
18
+ `fit` / `transform` / `predict_proba` / `fit_transform` / `decision_function` /
19
+ `save` interface and a top-level `load_calibrator` loader. `transform` and
20
+ `decision_function` run under `torch.no_grad()`.
21
+ - Support for 2D `(B, C, H, W)`, 3D `(B, C, D, H, W)` and general
22
+ `(B, C, *spatial)` inputs, with logits **or** probabilities, masks and
23
+ `ignore_index`.
24
+ - Calibrators, with the paper's shorthand as aliases:
25
+ - `TemperatureScaling` (`TS`), `EnsembleTemperatureScaling` (`ETS`),
26
+ `VectorScaling` (`VS`), `MatrixScaling` (`MS`), `DirichletCalibration` (`DC`);
27
+ - `TranslationInvariantMatrixScaling` (`MSc`): optimizes `C-1` free columns and
28
+ a common row sum, reconstructs the last column and regularizes the
29
+ reconstructed matrix;
30
+ - `ClassConditionalMatrixScaling` (`CMS`, `CDC`), `ArgmaxPreservingMatrixScaling`
31
+ (`CMSAP`, `CMSap`) and `OrderPreservingMatrixScaling` (`CMSOP`, `CMSop`):
32
+ one affine map per uncalibrated top class. All experts are optimized
33
+ **jointly** by default (one optimizer, one cross-entropy loss over every
34
+ voxel, regularization averaged across experts in the common logit space, as
35
+ in the paper); `independent_experts=True` fits each expert in its own loop.
36
+ - Configurable optimizer on every calibrator: `optimizer="adam"` (default) or
37
+ `optimizer="lbfgs"`, with per-optimizer `lr` / `max_iter` defaults; a
38
+ non-positive `max_iter` is rejected.
39
+ - Validation-based early stopping (`patience`, `min_delta`, `lr_patience`,
40
+ `lr_factor`; Adam only) with `fit(..., val_predictions=, val_targets=,
41
+ val_mask=)`: the iterate with the best validation NLL is kept, and the
42
+ learning rate can decay on plateaus.
43
+ - Calibration metrics: negative log-likelihood, expected calibration error
44
+ (ECE), average calibration error (ACE, unweighted over non-empty bins),
45
+ multiclass Brier score and `reliability_curve` / `ReliabilityCurve`.
46
+ - Optional plotting: `fiducio.plots.reliability_diagram` (matplotlib,
47
+ lazy-imported, `[plots]` extra; `metric="ece"|"ace"|None`).
48
+ - Helpers: `two_channel_from_binary` (single-channel sigmoid → two channels) and
49
+ `get_calibrator_class` (build a calibrator from its registered id).
50
+ - Registry-backed persistence (`save` / `load_calibrator`) that loads on CPU by
51
+ default, accepts `map_location`, avoids importing arbitrary module paths, and
52
+ warns on a major-version mismatch.
53
+ - Synthetic numerical references for MS, MSc, CDC, CMSap and CMSop against the
54
+ research implementation, an ensemble-pooling example and a paper
55
+ implementation guide (`reproducibility/`).
56
+ - Documentation (MkDocs Material), runnable CPU examples, a README with a
57
+ reliability figure (`examples/readme_figure.py`), locked uv development
58
+ environments and a CI matrix for Python 3.10, 3.11 and 3.12.
59
+
60
+ [Unreleased]: https://github.com/fiducio-ai/Fiducio/compare/v0.1.0...HEAD
61
+ [0.1.0]: https://github.com/fiducio-ai/Fiducio/releases/tag/v0.1.0
@@ -0,0 +1,51 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use Fiducio in your research, please cite the paper below."
3
+ title: "Fiducio: Model-agnostic post-hoc calibration for 2D and 3D semantic segmentation"
4
+ version: "0.1.0"
5
+ date-released: "2026-09-21"
6
+ authors:
7
+ - name: "Fiducio maintainers (fiducio-ai)"
8
+ repository-code: "https://github.com/fiducio-ai/Fiducio"
9
+ url: "https://fiducio-ai.github.io/Fiducio/"
10
+ license: "Apache-2.0"
11
+ type: software
12
+ keywords:
13
+ - calibration
14
+ - semantic segmentation
15
+ - uncertainty
16
+ - pytorch
17
+ abstract: >
18
+ Fiducio is a model-agnostic Python library for post-hoc calibration of 2D and
19
+ 3D semantic segmentation models. It provides a consistent fit / transform API
20
+ for temperature, vector, matrix, Dirichlet and class-conditional matrix scaling
21
+ calibrators that operate on logits or probabilities produced by any segmentation
22
+ model.
23
+ preferred-citation:
24
+ type: article
25
+ title: "Rethinking Post-Hoc Calibration in Semantic Segmentation"
26
+ authors:
27
+ - given-names: "Tristan"
28
+ family-names: "Kirscher"
29
+ - given-names: "Kim-Celine"
30
+ family-names: "Kahl"
31
+ - given-names: "Balint"
32
+ family-names: "Kovacs"
33
+ - given-names: "Maximilian R."
34
+ family-names: "Rokuss"
35
+ - given-names: "Klaus"
36
+ family-names: "Maier-Hein"
37
+ - given-names: "Xavier"
38
+ family-names: "Coubez"
39
+ - given-names: "Philippe"
40
+ family-names: "Meyer"
41
+ - given-names: "Sylvain"
42
+ family-names: "Faisan"
43
+ journal: "Transactions on Machine Learning Research"
44
+ issn: "2835-8856"
45
+ year: 2026
46
+ month: 9
47
+ url: "https://openreview.net/forum?id=xwNoSNxgxV"
48
+ identifiers:
49
+ - type: url
50
+ value: "https://arxiv.org/abs/2607.01902"
51
+ description: "arXiv preprint (arXiv:2607.01902)"
fiducio-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Fiducio maintainers (fiducio-ai)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ include CITATION.cff CHANGELOG.md mkdocs.yml
2
+ include uv.lock .python-version
3
+ recursive-include tests *.py *.json
4
+ recursive-include reproducibility *.py *.md
5
+ recursive-include docs *.md
6
+ recursive-include examples *.py
fiducio-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.4
2
+ Name: fiducio
3
+ Version: 0.1.0
4
+ Summary: Model-agnostic post-hoc calibration for 2D and 3D semantic segmentation
5
+ Author: Fiducio maintainers (fiducio-ai)
6
+ Maintainer: fiducio-ai
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/fiducio-ai/Fiducio
9
+ Project-URL: Documentation, https://fiducio-ai.github.io/Fiducio/
10
+ Project-URL: Repository, https://github.com/fiducio-ai/Fiducio
11
+ Project-URL: Issues, https://github.com/fiducio-ai/Fiducio/issues
12
+ Project-URL: Changelog, https://github.com/fiducio-ai/Fiducio/blob/main/CHANGELOG.md
13
+ Keywords: calibration,post-hoc calibration,semantic segmentation,uncertainty,temperature scaling,matrix scaling,dirichlet calibration,pytorch
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: numpy>=1.22
27
+ Requires-Dist: torch>=2.0
28
+ Provides-Extra: plots
29
+ Requires-Dist: matplotlib>=3.5; extra == "plots"
30
+ Provides-Extra: docs
31
+ Requires-Dist: mkdocs>=1.6; extra == "docs"
32
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
33
+ Requires-Dist: mkdocstrings[python]>=0.30; extra == "docs"
34
+ Provides-Extra: dev
35
+ Requires-Dist: fiducio[plots]; extra == "dev"
36
+ Requires-Dist: pytest>=8.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
38
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
39
+ Requires-Dist: mypy>=1.11; extra == "dev"
40
+ Requires-Dist: build>=1.0; extra == "dev"
41
+ Provides-Extra: all
42
+ Requires-Dist: fiducio[plots]; extra == "all"
43
+ Requires-Dist: fiducio[docs]; extra == "all"
44
+ Requires-Dist: fiducio[dev]; extra == "all"
45
+ Dynamic: license-file
46
+
47
+ # Fiducio
48
+
49
+ [![Tests](https://github.com/fiducio-ai/Fiducio/actions/workflows/tests.yml/badge.svg)](https://github.com/fiducio-ai/Fiducio/actions/workflows/tests.yml)
50
+ [![Docs](https://github.com/fiducio-ai/Fiducio/actions/workflows/docs.yml/badge.svg)](https://fiducio-ai.github.io/Fiducio/)
51
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
52
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://github.com/fiducio-ai/Fiducio/blob/main/LICENSE)
53
+
54
+ **Fiducio** is a model-agnostic Python library of **post-hoc calibrators for 2D
55
+ and 3D semantic segmentation**. Give it the logits or probabilities of any
56
+ segmentation model and a labelled calibration set, and a calibrator returns
57
+ better-calibrated probabilities without retraining the segmentation model.
58
+ It implements temperature, vector, matrix and Dirichlet scaling, their
59
+ translation-invariant variants, and the class-conditional (CDC, CMSap, CMSop)
60
+ calibrators introduced in our paper
61
+ [*Rethinking Post-Hoc Calibration in Semantic Segmentation*](https://arxiv.org/abs/2607.01902),
62
+ accepted at TMLR. Whether the segmentation is preserved depends on the
63
+ calibrator; see the guarantees below.
64
+
65
+ It works with PyTorch U-Net, nnU-Net, SegFormer or any model that produces
66
+ logits: Fiducio only ever sees `(B, C, *spatial)` tensors and never needs to know
67
+ the architecture.
68
+
69
+ ![Reliability diagrams of an over-confident model before and after calibration with TemperatureScaling and CMSop](https://raw.githubusercontent.com/fiducio-ai/Fiducio/main/docs/assets/reliability_before_after.png)
70
+
71
+ *Top-1 reliability diagrams on held-out synthetic data (regenerate with
72
+ [`examples/readme_figure.py`](https://github.com/fiducio-ai/Fiducio/blob/main/examples/readme_figure.py)).*
73
+
74
+ ## Install
75
+
76
+ For development from a checkout, use the committed uv lockfile:
77
+
78
+ ```bash
79
+ uv sync --locked
80
+ uv run --no-sync pytest
81
+ ```
82
+
83
+ This uses CPU PyTorch for development. See [CONTRIBUTING.md](https://github.com/fiducio-ai/Fiducio/blob/main/CONTRIBUTING.md)
84
+ for the pinned uv version, documentation and build commands.
85
+
86
+ For an existing uv application before the first PyPI release:
87
+
88
+ ```bash
89
+ uv add "fiducio @ git+https://github.com/fiducio-ai/Fiducio.git"
90
+ ```
91
+
92
+ Once a PyPI release is available, the standard installation is:
93
+
94
+ ```bash
95
+ pip install fiducio
96
+ ```
97
+
98
+ With pip, before the first PyPI release, install from GitHub:
99
+
100
+ ```bash
101
+ pip install "git+https://github.com/fiducio-ai/Fiducio.git"
102
+ ```
103
+
104
+ The core install depends only on `numpy` and `torch`. Optional extras:
105
+ `fiducio[plots]` (matplotlib reliability diagrams), `fiducio[docs]`,
106
+ `fiducio[dev]`, `fiducio[all]`.
107
+
108
+ ## Quick start
109
+
110
+ ```python
111
+ import torch
112
+ from fiducio import TemperatureScaling, load_calibrator
113
+
114
+ # From a held-out, labelled calibration set:
115
+ logits = torch.randn(8, 4, 64, 64) # (B, C, H, W) model logits
116
+ labels = torch.randint(0, 4, (8, 64, 64)) # (B, H, W) labels
117
+
118
+ calibrator = TemperatureScaling(input_type="logits").fit(logits, labels)
119
+
120
+ # Apply to new predictions (returns calibrated probabilities):
121
+ probs = calibrator.transform(torch.randn(2, 4, 64, 64))
122
+
123
+ # Save and reload (loads on CPU by default):
124
+ calibrator.save("calibrator.pt")
125
+ calibrator = load_calibrator("calibrator.pt")
126
+ ```
127
+
128
+ Every calibrator exposes the same API:
129
+ `fit(predictions, targets, mask=None)`, `transform`, `predict_proba`,
130
+ `fit_transform`, `save`, and the top-level `load_calibrator`.
131
+
132
+ ## Accepted tensor shapes
133
+
134
+ The class axis is **always** dimension 1.
135
+
136
+ | Use case | `predictions` | `targets` |
137
+ |----------|---------------|-----------|
138
+ | 2D segmentation | `(B, C, H, W)` | `(B, H, W)` |
139
+ | 3D segmentation | `(B, C, D, H, W)` | `(B, D, H, W)` |
140
+ | general n-D | `(B, C, *spatial)` | `(B, *spatial)` |
141
+ | per-pixel table | `(N, C)` | `(N,)` |
142
+
143
+ Inputs may be `logits` or `probs` (set `input_type`). Binary segmentation is two
144
+ channels (`C = 2`). `mask` and `ignore_index` exclude voxels from fitting.
145
+
146
+ ## Calibrators
147
+
148
+ | Class | Alias | Translation-invariant | Decision preservation |
149
+ |-------|-------|:---------------------:|-----------------------|
150
+ | `TemperatureScaling` | `TS` | yes | argmax and full order |
151
+ | `EnsembleTemperatureScaling` | `ETS` | yes | argmax and full order |
152
+ | `VectorScaling` | `VS` | no | — |
153
+ | `MatrixScaling` | `MS` | no | — |
154
+ | `TranslationInvariantMatrixScaling` | `MSc` | yes | — |
155
+ | `DirichletCalibration` | `DC` | yes | — |
156
+ | `ClassConditionalMatrixScaling` | `CMS` / `CDC` | yes | — |
157
+ | `ArgmaxPreservingMatrixScaling` | `CMSAP` / `CMSap` | yes | argmax |
158
+ | `OrderPreservingMatrixScaling` | `CMSOP` / `CMSop` | yes | argmax and full order |
159
+
160
+ Translation-invariant means the output is unchanged when the same constant is
161
+ added to every input logit of a voxel.
162
+
163
+ Every calibrator also exposes `decision_function` (calibrated logits) and a
164
+ configurable `optimizer` (`"adam"` default, or `"lbfgs"`).
165
+
166
+ ### Early stopping
167
+
168
+ Adam-fitted calibrators support the paper's recipe of early stopping on a
169
+ validation set (with an optional learning-rate decay on plateaus):
170
+
171
+ ```python
172
+ from fiducio import OrderPreservingMatrixScaling
173
+
174
+ calibrator = OrderPreservingMatrixScaling(max_iter=2000, patience=20, lr_patience=10)
175
+ calibrator.fit(
176
+ logits, labels,
177
+ val_predictions=val_logits, val_targets=val_labels, # held out from both
178
+ )
179
+ ```
180
+
181
+ The iterate with the best validation NLL is kept. The default fixed budget
182
+ (`max_iter`) is short, so it can underfit expressive calibrators; prefer a larger
183
+ `max_iter` together with `patience` for CDC, CMSap and CMSop.
184
+
185
+ ### Paper method mapping
186
+
187
+ | Paper method | Class |
188
+ |--------------|-------|
189
+ | TS | `TemperatureScaling` |
190
+ | MS | `MatrixScaling` |
191
+ | MSc | `TranslationInvariantMatrixScaling` |
192
+ | CDC | `ClassConditionalMatrixScaling` |
193
+ | CMSap | `ArgmaxPreservingMatrixScaling` |
194
+ | CMSop | `OrderPreservingMatrixScaling` |
195
+
196
+ CDC, CMSap and CMSop are class-conditional: they fit one affine map per
197
+ uncalibrated top class, all experts optimized **jointly** by a single
198
+ optimizer minimizing one cross-entropy loss over every voxel at once, with L2
199
+ regularization (`lambda_reg` / `mu_reg`) applied to the affine map induced in
200
+ the common *logit* space rather than to the raw per-expert parameters — this
201
+ keeps the regularization meaningful for CMSap/CMSop, whose parameters are
202
+ non-negative margins/gaps rather than raw matrix entries. Pass
203
+ `independent_experts=True` to instead fit each expert in its own optimization
204
+ loop on only the voxels routed to it.
205
+
206
+ Calibration metrics are included: `negative_log_likelihood`,
207
+ `expected_calibration_error` (ECE, population-weighted), `average_calibration_error`
208
+ (ACE, unweighted over the same bins — doesn't let a sparsely populated bin get
209
+ drowned out by a large one), `brier_score`, `reliability_curve`, plus an
210
+ optional reliability-diagram plot (`fiducio.plots.reliability_diagram`, needs
211
+ `fiducio[plots]`).
212
+
213
+ ## Documentation
214
+
215
+ The [paper implementation guide](https://github.com/fiducio-ai/Fiducio/blob/main/reproducibility/README.md) records method
216
+ mapping, numerical-reference coverage, fitting limits and the remaining steps
217
+ needed to reproduce the paper's experiments. For ensemble inputs, see
218
+ [`examples/ensemble_pooling.py`](https://github.com/fiducio-ai/Fiducio/blob/main/examples/ensemble_pooling.py).
219
+
220
+ ### Results in the paper
221
+
222
+ The paper compares these calibrators on real segmentation benchmarks. The
223
+ reliability diagrams below (paper appendix) show the uncalibrated ensemble
224
+ pooling (`p0`, `p̄`) against the best calibrator per dataset; the exact
225
+ protocol, datasets and metrics are in the paper. This repository ships the
226
+ calibrators, not the fitted models or benchmark pipelines, so it does not
227
+ regenerate these figures (see the
228
+ [implementation guide](https://github.com/fiducio-ai/Fiducio/blob/main/reproducibility/README.md)).
229
+
230
+ ![Reliability diagrams from the paper on three datasets](https://raw.githubusercontent.com/fiducio-ai/Fiducio/main/docs/assets/paper_reliability.png)
231
+
232
+ Full guide and API reference: **https://fiducio-ai.github.io/Fiducio/**
233
+
234
+ - [Installation](https://fiducio-ai.github.io/Fiducio/installation/)
235
+ - [Quickstart](https://fiducio-ai.github.io/Fiducio/quickstart/)
236
+ - [Concepts](https://fiducio-ai.github.io/Fiducio/concepts/)
237
+ - [Calibrators](https://fiducio-ai.github.io/Fiducio/calibrators/)
238
+ - [Examples](https://fiducio-ai.github.io/Fiducio/examples/)
239
+
240
+ ## Citation
241
+
242
+ Fiducio accompanies the paper *Rethinking Post-Hoc Calibration in Semantic
243
+ Segmentation* (Kirscher et al., Transactions on Machine Learning Research, 2026;
244
+ [OpenReview](https://openreview.net/forum?id=xwNoSNxgxV), preprint: [arXiv:2607.01902](https://arxiv.org/abs/2607.01902)).
245
+ If you use Fiducio in your research, please cite it using the metadata in
246
+ [`CITATION.cff`](https://github.com/fiducio-ai/Fiducio/blob/main/CITATION.cff), or:
247
+
248
+ ```bibtex
249
+ @article{kirscher2026rethinking,
250
+ title = {Rethinking Post-Hoc Calibration in Semantic Segmentation},
251
+ author = {Kirscher, Tristan and Kahl, Kim-Celine and Kovacs, Balint and
252
+ Rokuss, Maximilian and Maier-Hein, Klaus and Coubez, Xavier and
253
+ Meyer, Philippe and Faisan, Sylvain},
254
+ journal = {Transactions on Machine Learning Research},
255
+ issn = {2835-8856},
256
+ year = {2026},
257
+ url = {https://openreview.net/forum?id=xwNoSNxgxV}
258
+ }
259
+ ```
260
+
261
+ ## Status
262
+
263
+ Fiducio is **beta** (`0.x`): usable and tested, with an API that may still change
264
+ before `1.0`. It is not certified for safety-critical or clinical use.
265
+
266
+ ## License
267
+
268
+ [Apache-2.0](https://github.com/fiducio-ai/Fiducio/blob/main/LICENSE).