litecalib 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 (61) hide show
  1. litecalib-0.1.0/LICENSE +201 -0
  2. litecalib-0.1.0/NOTICE +9 -0
  3. litecalib-0.1.0/PKG-INFO +353 -0
  4. litecalib-0.1.0/README.md +313 -0
  5. litecalib-0.1.0/litecalib/__init__.py +17 -0
  6. litecalib-0.1.0/litecalib/anycalib/LICENSE +201 -0
  7. litecalib-0.1.0/litecalib/anycalib/README +3 -0
  8. litecalib-0.1.0/litecalib/anycalib/__init__.py +1 -0
  9. litecalib-0.1.0/litecalib/anycalib/cameras/__init__.py +17 -0
  10. litecalib-0.1.0/litecalib/anycalib/cameras/base.py +544 -0
  11. litecalib-0.1.0/litecalib/anycalib/cameras/division.py +527 -0
  12. litecalib-0.1.0/litecalib/anycalib/cameras/eucm.py +570 -0
  13. litecalib-0.1.0/litecalib/anycalib/cameras/factory.py +245 -0
  14. litecalib-0.1.0/litecalib/anycalib/cameras/fov.py +203 -0
  15. litecalib-0.1.0/litecalib/anycalib/cameras/kannala_brandt.py +537 -0
  16. litecalib-0.1.0/litecalib/anycalib/cameras/pinhole.py +315 -0
  17. litecalib-0.1.0/litecalib/anycalib/cameras/radial.py +600 -0
  18. litecalib-0.1.0/litecalib/anycalib/cameras/simple_division.py +39 -0
  19. litecalib-0.1.0/litecalib/anycalib/cameras/simple_eucm.py +51 -0
  20. litecalib-0.1.0/litecalib/anycalib/cameras/simple_kannala_brandt.py +90 -0
  21. litecalib-0.1.0/litecalib/anycalib/cameras/simple_pinhole.py +123 -0
  22. litecalib-0.1.0/litecalib/anycalib/cameras/simple_radial.py +90 -0
  23. litecalib-0.1.0/litecalib/anycalib/cameras/simple_ucm.py +27 -0
  24. litecalib-0.1.0/litecalib/anycalib/cameras/ucm.py +438 -0
  25. litecalib-0.1.0/litecalib/anycalib/manifolds.py +361 -0
  26. litecalib-0.1.0/litecalib/anycalib/model/__init__.py +1 -0
  27. litecalib-0.1.0/litecalib/anycalib/model/anycalib_pretrained.py +434 -0
  28. litecalib-0.1.0/litecalib/anycalib/model/dinov2.py +132 -0
  29. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/__init__.py +11 -0
  30. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/attention.py +91 -0
  31. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/block.py +260 -0
  32. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/dino_head.py +58 -0
  33. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/drop_path.py +34 -0
  34. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/layer_scale.py +27 -0
  35. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/mlp.py +40 -0
  36. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/patch_embed.py +88 -0
  37. litecalib-0.1.0/litecalib/anycalib/model/dinov2_layers/swiglu_ffn.py +72 -0
  38. litecalib-0.1.0/litecalib/anycalib/model/dpt_light_decoder.py +144 -0
  39. litecalib-0.1.0/litecalib/anycalib/model/ray_decoder.py +77 -0
  40. litecalib-0.1.0/litecalib/anycalib/model/vision_transformer.py +439 -0
  41. litecalib-0.1.0/litecalib/anycalib/optim/__init__.py +2 -0
  42. litecalib-0.1.0/litecalib/anycalib/optim/gauss_newton.py +374 -0
  43. litecalib-0.1.0/litecalib/anycalib/optim/lev_mar.py +173 -0
  44. litecalib-0.1.0/litecalib/anycalib/ransac.py +257 -0
  45. litecalib-0.1.0/litecalib/anycalib/utils.py +195 -0
  46. litecalib-0.1.0/litecalib/calibrator_cpu.py +693 -0
  47. litecalib-0.1.0/litecalib/calibrator_cuda.py +762 -0
  48. litecalib-0.1.0/litecalib/cli.py +47 -0
  49. litecalib-0.1.0/litecalib/fit.py +315 -0
  50. litecalib-0.1.0/litecalib/geometry.py +508 -0
  51. litecalib-0.1.0/litecalib/hub.py +33 -0
  52. litecalib-0.1.0/litecalib/model.py +427 -0
  53. litecalib-0.1.0/litecalib/predictor.py +390 -0
  54. litecalib-0.1.0/litecalib.egg-info/PKG-INFO +353 -0
  55. litecalib-0.1.0/litecalib.egg-info/SOURCES.txt +59 -0
  56. litecalib-0.1.0/litecalib.egg-info/dependency_links.txt +1 -0
  57. litecalib-0.1.0/litecalib.egg-info/entry_points.txt +2 -0
  58. litecalib-0.1.0/litecalib.egg-info/requires.txt +21 -0
  59. litecalib-0.1.0/litecalib.egg-info/top_level.txt +1 -0
  60. litecalib-0.1.0/pyproject.toml +61 -0
  61. litecalib-0.1.0/setup.cfg +4 -0
@@ -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
95
+ Derivative 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 [yyyy] [name of copyright owner]
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.
litecalib-0.1.0/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ LiteCalib
2
+
3
+ This product includes software from AnyCalib (https://github.com/javrtg/AnyCalib), licensed under the
4
+ Apache License, Version 2.0: the camera models, the calibrator, the DPT decoder and ray head, and the vendored
5
+ DINOv2 vision transformer in litecalib/anycalib/ (imports rewritten), and the Numba port of AnyCalib's
6
+ calibrator in litecalib/calibrator_cpu.py and litecalib/calibrator_cuda.py.
7
+
8
+ AnyCalib in turn includes code from DINOv2 (https://github.com/facebookresearch/dinov2), licensed under the
9
+ Apache License, Version 2.0.
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: litecalib
3
+ Version: 0.1.0
4
+ Summary: Lightweight single-image camera calibration from a sparse field-of-view field
5
+ Author: Viktor Kocur, Lukas Bujnak
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/kocurvik/litecalib
8
+ Project-URL: Models, https://huggingface.co/LiteCalib
9
+ Project-URL: Dataset, https://huggingface.co/datasets/LiteCalib/CommonsPano
10
+ Keywords: camera calibration,intrinsics,lens distortion,computer vision,deep learning
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ License-File: NOTICE
18
+ License-File: litecalib/anycalib/LICENSE
19
+ Requires-Dist: torch>=2.1
20
+ Requires-Dist: numpy
21
+ Requires-Dist: numba>=0.59
22
+ Requires-Dist: safetensors
23
+ Requires-Dist: huggingface_hub
24
+ Requires-Dist: pillow
25
+ Requires-Dist: scipy
26
+ Provides-Extra: train
27
+ Requires-Dist: torchvision; extra == "train"
28
+ Requires-Dist: h5py; extra == "train"
29
+ Requires-Dist: omegaconf; extra == "train"
30
+ Requires-Dist: pyyaml; extra == "train"
31
+ Requires-Dist: tqdm; extra == "train"
32
+ Requires-Dist: albumentations==1.4.*; extra == "train"
33
+ Requires-Dist: opencv-python; extra == "train"
34
+ Requires-Dist: kornia; extra == "train"
35
+ Requires-Dist: requests; extra == "train"
36
+ Requires-Dist: pandas; extra == "train"
37
+ Requires-Dist: matplotlib; extra == "train"
38
+ Requires-Dist: submitit; extra == "train"
39
+ Dynamic: license-file
40
+
41
+ # LiteCalib: Fast, Model-Agnostic Single-View Camera Calibration
42
+
43
+ Viktor Kocur<sup>1</sup>, Lukáš Bujňák<sup>1</sup>, Lukáš Gajdošech<sup>1</sup>, Torsten Sattler<sup>2</sup>,
44
+ Zuzana Kukelova<sup>3</sup>
45
+
46
+ <sup>1</sup> Faculty of Mathematics, Physics and Informatics, Comenius University in Bratislava<br>
47
+ <sup>2</sup> Czech Institute of Informatics, Robotics and Cybernetics, Czech Technical University in Prague<br>
48
+ <sup>3</sup> Visual Recognition Group, Faculty of Electrical Engineering, Czech Technical University in Prague
49
+
50
+ **Lightweight single-image camera calibration.** Given one image, LiteCalib estimates the camera's
51
+ intrinsics (focal length and lens distortion) for any radially symmetric camera model: pinhole,
52
+ Brown-Conrady, Kannala-Brandt, UCM or the division model.
53
+
54
+ Dense methods such as [AnyCalib](https://github.com/javrtg/AnyCalib) predict a ray for every pixel and
55
+ then fit a camera model to all of them. LiteCalib instead predicts the camera's **field of view at a
56
+ 5 x 5 grid of image points**: for each point, the angles `(atan2(X, Z), atan2(Y, Z))` of its ray. A small
57
+ query decoder on a DINOv2 backbone reads these 25 points out of the image tokens; no dense decoder runs at
58
+ inference. The camera model is then fitted to the 25 rays with AnyCalib's calibrator, compiled with Numba,
59
+ with the principal point at the image center and square pixels.
60
+
61
+ During training, a dense branch (AnyCalib's DPT decoder and ray head) supervises the backbone with
62
+ per-pixel rays. It is dropped at inference, so it costs nothing at test time.
63
+
64
+ | model | Hugging Face | backbone | params |
65
+ |---|---|---|---|
66
+ | `litecalib_vitl` | [LiteCalib/litecalib-vitl](https://huggingface.co/LiteCalib/litecalib-vitl) | DINOv2 ViT-L/14 | 338 M |
67
+ | `litecalib_vitb` | [LiteCalib/litecalib-vitb](https://huggingface.co/LiteCalib/litecalib-vitb) | DINOv2 ViT-B/14 | 106 M |
68
+ | `litecalib_vits` | [LiteCalib/litecalib-vits](https://huggingface.co/LiteCalib/litecalib-vits) | DINOv2 ViT-S/14 | 27 M |
69
+ | `anycalib_litecalib_data_vitl` | [LiteCalib/anycalib-litecalib-data-vitl](https://huggingface.co/LiteCalib/anycalib-litecalib-data-vitl) | AnyCalib's network, trained on our data | 320 M |
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ pip install litecalib
75
+ ```
76
+
77
+ This installs the inference package: the networks, the compiled calibrator and the camera models. It needs
78
+ PyTorch and Numba. The weights are downloaded from the Hugging Face hub (one repository per model, under
79
+ [LiteCalib](https://huggingface.co/LiteCalib)) on first use.
80
+
81
+ ## Usage
82
+
83
+ ```python
84
+ import litecalib
85
+
86
+ model = litecalib.load("litecalib_vitl") # or litecalib_vitb / litecalib_vits / a local checkpoint
87
+
88
+ calib = model.calibrate("photo.jpg", cam_id="radial:1")
89
+ calib.K # (1, 3, 3) calibration matrix, in pixels of the original image
90
+ calib.distortion # (1, 1) tensor [[k1]]
91
+ undistorted = calib.undistort("photo.jpg") # (1, 3, H, W) in [0, 1], a pinhole image
92
+
93
+ # several photos taken with one camera: fit a single camera to all of them
94
+ calib = model.calibrate(["a.jpg", "b.jpg", "c.jpg"], cam_id="kb:4", shared=True)
95
+ undistorted = calib.undistort(["a.jpg", "b.jpg", "c.jpg"]) # the same camera applied to each
96
+ K, dist = calib.to_opencv() # for cv2.fisheye
97
+ ```
98
+
99
+ [`notebooks/reconstruction.ipynb`](notebooks/reconstruction.ipynb)
100
+ ([Colab](https://colab.research.google.com/github/kocurvik/litecalib/blob/main/notebooks/reconstruction.ipynb))
101
+ calibrates ten fisheye photos from Zip-NeRF with LiteCalib (the one-parameter division model), undistorts them and
102
+ reconstructs the scene with Pi3X, with and without the calibration.
103
+
104
+ From the command line, printing each calibration as JSON:
105
+
106
+ ```bash
107
+ litecalib photo1.jpg photo2.jpg --cam kb:4 --model litecalib_vits --undistort_dir undistorted/
108
+ litecalib frames/*.jpg --cam radial:2 --shared # one camera for all frames
109
+ ```
110
+
111
+ ## API
112
+
113
+ ### `litecalib.load(name="litecalib_vitl", device=None) -> Calibrator`
114
+
115
+ Loads a released model by name (`litecalib_vitl`, `litecalib_vitb`, `litecalib_vits`, `anycalib_litecalib_data_vitl`)
116
+ or by Hugging Face repository id (`LiteCalib/litecalib-vitl`), downloaded from the hub and cached, or a local
117
+ checkpoint: a released model's folder (`model.safetensors` + `config.json`), its `.safetensors` file, or a
118
+ training `.pt`.
119
+ `device` is where the network runs (default: CUDA if available).
120
+
121
+ ### `Calibrator.calibrate(images, cam_id="pinhole", shared=False, ...) -> Calibration`
122
+
123
+ Predicts the rays and fits the camera model in one call.
124
+
125
+ | argument | default | meaning |
126
+ |---|---|---|
127
+ | `images` | | a path, a PIL image (any mode; converted to RGB), an `(H, W, 3)` uint8 RGB array, a `(3, H, W)` or `(B, 3, H, W)` tensor in `[0, 1]`, or a list of these; all images of one call must have the same size |
128
+ | `cam_id` | `"pinhole"` | the camera model to fit (table below) |
129
+ | `shared` | `False` | `False`: one camera per image. `True`: one camera fitted jointly to the rays of all images (images taken with one camera at one zoom) |
130
+ | `fixed_center` | `True` for LiteCalib, `False` for AnyCalib models | hold the principal point at the image center; `False` estimates it (for cropped images) |
131
+ | `square_pixels` | as `fixed_center` | one focal length; `False` fits `fx` and `fy` separately (for stretched images); needs `fixed_center` |
132
+ | `iters` | `2` | Gauss-Newton iterations of the calibrator |
133
+ | `fit_device` | `"cpu"` | where the fit runs: `"cpu"` (Numba) or `"cuda"` (Numba CUDA) |
134
+ | `batch_size` | `8` | images per network forward |
135
+
136
+ The defaults are the fit used in the paper. With `square_pixels`, `fx` and `fy` can still differ by a fraction
137
+ of a pixel: the camera is fitted in the network's resized input and mapped back to the original image, and
138
+ the two axes are scaled slightly differently.
139
+
140
+ Supported camera models, in AnyCalib's notation (the first compiled call of each takes a few seconds while
141
+ Numba compiles it; it is cached afterwards):
142
+
143
+ | `cam_id` | model | distortion coefficients |
144
+ |---|---|---|
145
+ | `pinhole` | pinhole | none |
146
+ | `radial:1` ... `radial:3` | Brown-Conrady, radial terms only (OpenCV's `k1, k2, k3`) | `k1[, k2, k3]` |
147
+ | `kb:1` ... `kb:4` | Kannala-Brandt (OpenCV's fisheye model with `kb:4`) | `k1, ..., k4` |
148
+ | `ucm` | unified camera model | `xi` |
149
+ | `division:1`, `division:2` | division model | `k1[, k2]` |
150
+
151
+ ### `Calibration`
152
+
153
+ The result: B cameras for B images, or one camera when `shared=True`. All values are in pixels of the
154
+ original images, with the origin at the top-left corner of the top-left pixel (AnyCalib's convention).
155
+
156
+ | member | type | meaning |
157
+ |---|---|---|
158
+ | `cam_id` | `str` | the fitted model |
159
+ | `intrinsics` | `(B, D)` float64 tensor | `fx, fy, cx, cy` followed by the distortion coefficients |
160
+ | `K` | `(B, 3, 3)` tensor | calibration matrices |
161
+ | `distortion` | `(B, nk)` tensor | distortion coefficients, named by `distortion_names` (e.g. `["k1", "k2"]`) |
162
+ | `image_size` | `(h, w)` | size of the calibrated images |
163
+ | `num_images`, `shared` | `int`, `bool` | how many images were calibrated, and whether jointly |
164
+ | `camera` | AnyCalib camera | the model itself: `camera.project(intrinsics, points)`, `camera.unproject(intrinsics, pixels)` |
165
+ | `fov()` | `{"vfov", "hfov"}` | fields of view in degrees, `(B,)` each |
166
+ | `undistort(images, scale=1.0, size=None)` | `(B, 3, h, w)` tensor | the images resampled to the pinhole camera `undistorted_K(scale, size)` (black where the camera sees nothing); one camera is applied to every image given, B cameras need B images |
167
+ | `undistorted_K(scale=1.0, size=None)` | `(B, 3, 3)` tensor | the intrinsics of those pinhole images: the focal lengths times `scale` (`< 1` zooms out, keeping more of a wide field of view), the principal point kept, or at the center of an output of `size` (h, w) |
168
+ | `to_opencv()` | `(K, dist)` numpy | `pinhole` / `radial:K`: `dist = (k1, k2, 0, 0, k3)` for `cv2.undistort`; `kb:4`: the four coefficients of `cv2.fisheye`; the principal point is shifted by -0.5 to OpenCV's pixel-center origin |
169
+ | `calib[i]` | `Calibration` | the camera of image `i` |
170
+ | `to_dict()`, `Calibration.from_dict(d)` | | plain values, e.g. to save as JSON and load later |
171
+
172
+ ### Lower level
173
+
174
+ `Calibrator.predict_rays(images, batch_size=8)` runs only the network. It returns `rays`, `(B, N, 3)` unit
175
+ rays (N = 25 for LiteCalib, every pixel for AnyCalib models), at the pixels `x`, `(N, 2)`, of the resized
176
+ network input `(ht, wt)`, together with the map from original pixels to input pixels (`scale_xy`,
177
+ `shift_xy`). `Calibrator.fit(pred, cam_id, shared=False, ...)` fits a camera model to that output and takes the
178
+ same options as `calibrate`. To try several camera models on the same images, predict once and fit each:
179
+
180
+ ```python
181
+ pred = model.predict_rays(["a.jpg", "b.jpg"])
182
+ calibs = {cam: model.fit(pred, cam, shared=True) for cam in ("radial:1", "kb:4", "division:1")}
183
+ ```
184
+
185
+ ## Repository
186
+
187
+ The repository also contains everything needed to reproduce the paper: data preparation, training and
188
+ evaluation.
189
+
190
+ ```
191
+ litecalib/ the pip package: model.py (network), predictor.py (calibration API), calibrator_{cpu,cuda}.py
192
+ (AnyCalib's calibrator in Numba), geometry.py, fit.py, anycalib/ (vendored from AnyCalib)
193
+ train/ train.py (LiteCalib and the ablations), train_anycalib.py (AnyCalib's network), losses
194
+ eval/ evaluate.py (benchmarks, efficiency), sparse.py (AnyCalib's calibrator on sparse pixels),
195
+ edit_intrinsics.py (edited images), metrics.py, download_benchmarks.py
196
+ data_utils/ panorama view rendering, MegaScenes and benchmark preparation
197
+ configs/ training configs of every model in the paper, view generation configs, data paths
198
+ data.py, gt.py data loading and ground truth; paths.py, slurm.py, vendor.py: plumbing
199
+ scripts/ export_release.py (training checkpoint -> a released model's folder: weights, config, model card)
200
+ third_party/ AnyCalib as a git submodule (its siclib: augmentations, view sampling, benchmark URLs)
201
+ ```
202
+
203
+ ```bash
204
+ git clone --recursive https://github.com/kocurvik/litecalib
205
+ cd litecalib
206
+ pip install -e ".[train]"
207
+ ```
208
+
209
+ `albumentations` must be 1.4.x: newer versions silently ignore some of AnyCalib's augmentation settings
210
+ (`train/train.py` refuses to start in that case).
211
+
212
+ ### Data
213
+
214
+ Set the data roots of your machine in `configs/paths/local.yaml` (or create another file and select it with
215
+ `LITECALIB_PATHS=<name>`); `python paths.py` lists them.
216
+
217
+ **Benchmarks.** AnyCalib's benchmarks are downloaded by `python eval/download_benchmarks.py --sets table2 table3
218
+ edit`; ScanNet++ needs a personal token (`data_utils/prepare_scannetpp.py`). InFlux and InFlux++ are built from
219
+ InFlux-Real's validation split by `data_utils/prepare_influx_real.py`, and Cathedral from its SfM
220
+ reconstruction by `data_utils/prepare_rd.py`.
221
+
222
+ **Training data.**
223
+
224
+ - OpenPano: AnyCalib's extended OpenPano panoramas (see AnyCalib's instructions), in
225
+ `<openpano_root>/panoramas/{train,val,test}`.
226
+ - CommonsPano: our 360° panoramas from Wikimedia Commons, on the Hugging Face hub at
227
+ [LiteCalib/CommonsPano](https://huggingface.co/datasets/LiteCalib/CommonsPano), in two subsets: `by` (public
228
+ domain / CC0 / CC BY) and `by-sa` (CC BY-SA), each with `train` and `validation` folders. The view generator
229
+ reads `<root>/panoramas/{train,val}`, `commons_root` for `by` and `commons_sa_root` for `by-sa`; download the
230
+ dataset and copy the images there (only the `.jpg` files: each folder also holds a `metadata.csv`):
231
+
232
+ ```bash
233
+ hf download LiteCalib/CommonsPano --repo-type dataset --local-dir commons_download
234
+ for pair in by:/data/commons_pano by-sa:/data/commons_pano_sa; do # <subset>:<commons_root / commons_sa_root>
235
+ subset=${pair%%:*}; root=${pair#*:}
236
+ mkdir -p "$root/panoramas/train" "$root/panoramas/val"
237
+ cp commons_download/$subset/train/*.jpg "$root/panoramas/train/"
238
+ cp commons_download/$subset/validation/*.jpg "$root/panoramas/val/"
239
+ cp commons_download/attribution.csv "$root/"
240
+ done
241
+ ```
242
+
243
+ Keep `attribution.csv` with anything derived from it.
244
+ - Views are rendered from the panoramas with AnyCalib's camera sampling: `python data_utils/generate_views.py
245
+ openpano_v2_gen` (likewise `commons_gen` and `commons_sa_gen`, and `openpano_v2` for perspective views). Each
246
+ split is written as one HDF5 store. The released models were trained on all three panorama view sets as one
247
+ share and MegaScenes as the other.
248
+ - MegaScenes: real photos with COLMAP's radial cameras, `python data_utils/prepare_megascenes.py` (fetched over
249
+ anonymous HTTP from the MegaScenes S3 bucket, scene by scene).
250
+
251
+ ### Training
252
+
253
+ Each model of the paper has a config in `configs/`:
254
+
255
+ | config | model |
256
+ |---|---|
257
+ | `ms_aux_field_wsd24_k5_{vitl,vitb,vits}_opg.yaml` | LiteCalib (the released models) |
258
+ | `ms_ac_wsd24_{vitl,vits}_opg.yaml` | AnyCalib's network on the same data (`train/train_anycalib.py`) |
259
+ | `ms_field_wsd24_k5_vitl_opg.yaml` | ablation: no dense branch |
260
+ | `ms_aux_field_wsd24_vitl_opg.yaml` | ablation: 7 x 7 grid |
261
+ | `ms_aux_field_wsd24_k5_logmap_vitl_opg.yaml` | ablation: AnyCalib's log map instead of the FoV field |
262
+ | `ms_auxfov_field_wsd24_k5_vitl_opg.yaml` | ablation: dense branch supervised in the FoV field |
263
+ | `ms_aux_wsd24_vitl_opg.yaml` | ablation: radial angle profile |
264
+ | `ms_aux_div_wsd24_vitl_opg.yaml` | ablation: direct regression of the division model |
265
+ | `opg_*`, `pano_*`, `opgms_*`, `e1_aux_field_k5_vitl_opg.yaml` | training data ablations |
266
+ | `e1_aux_field_k5_edit_vitl_opp.yaml` | edited (cropped, stretched) images |
267
+
268
+ ```bash
269
+ python train/train.py --config configs/ms_aux_field_wsd24_k5_vitl_opg.yaml
270
+ python train/train_anycalib.py --config configs/ms_ac_wsd24_vitl_opg.yaml
271
+ ```
272
+
273
+ The ViT-L runs used one GPU with batch 24 for about a day. Every script takes `--submitit` to submit itself
274
+ to SLURM with the same arguments; set your account and partitions in `slurm.py` (the defaults there are
275
+ examples) and the data roots in `configs/paths/cluster.yaml`. For a quick check of the whole path, add
276
+ `--limit_train 64 --limit_val 16 --epochs 1`.
277
+
278
+ ### Evaluation
279
+
280
+ ```bash
281
+ # LiteCalib: AnyCalib's calibrator on the 25 rays, c at the image center, one focal (the paper's fit)
282
+ python eval/evaluate.py --model checkpoints/<ckpt>.pt --data stanford2d3d tartanair megadepth2k lamar2k \
283
+ megadepth2k-radial scannetpp2k monovo2k influx_val influx_pp_val cathedral --efficiency
284
+ # the radial-profile and direct-regression ablations
285
+ python eval/evaluate.py --model checkpoints/<radial or division ckpt>.pt --fit it2 --data ...
286
+ # AnyCalib's released model or AnyCalib's network trained here, its own calibrator on the dense field
287
+ python eval/evaluate.py --model anycalib_gen checkpoints/<anycalib ckpt>.pt --data ...
288
+ # the sparse-field study: AnyCalib's calibrator on an N x N grid of pixels, PyTorch or compiled
289
+ python eval/evaluate.py --model anycalib_gen --anycalib_sampling dense egrid:5 acnb_egrid:5:it2 \
290
+ --anycalib_c free square --fit_device cpu cuda --data ...
291
+ # edited images: focal and principal point errors (c, fx and fy free)
292
+ python eval/edit_intrinsics.py --model checkpoints/<edit ckpt>.pt anycalib_edit
293
+ ```
294
+
295
+ Each benchmark is fitted with its own camera model (`eval/metrics.py`); the metrics are AnyCalib's.
296
+
297
+ ### Releasing
298
+
299
+ ```bash
300
+ python scripts/export_release.py --ckpt litecalib_vitl=checkpoints/<vitl>.pt litecalib_vitb=checkpoints/<vitb>.pt \
301
+ litecalib_vits=checkpoints/<vits>.pt anycalib_litecalib_data_vitl=checkpoints/<anycalib vitl>.pt --out release
302
+ huggingface-cli upload LiteCalib/litecalib-vitl release/litecalib_vitl .
303
+ huggingface-cli upload LiteCalib/litecalib-vitb release/litecalib_vitb .
304
+ huggingface-cli upload LiteCalib/litecalib-vits release/litecalib_vits .
305
+ huggingface-cli upload LiteCalib/anycalib-litecalib-data-vitl release/anycalib_litecalib_data_vitl .
306
+ ```
307
+
308
+ Each folder is one model's repository: `model.safetensors`, `config.json` and the model card `README.md`
309
+ (Apache 2.0, the training data with the Laval link).
310
+
311
+ The PyPI package is built and uploaded by `.github/workflows/release.yml` when a GitHub release is published
312
+ (PyPI trusted publishing); the release tag must match `litecalib.__version__`.
313
+
314
+ ## Datasets
315
+
316
+ The released models are trained on three sources of images:
317
+
318
+ - **OpenPano** (extended, `openpano_v2`). OpenPano was introduced by GeoCalib, which describes how its panoramas
319
+ were collected and split ([GeoCalib: OpenPano Dataset](https://github.com/cvg/GeoCalib?tab=readme-ov-file#openpano-dataset)).
320
+ AnyCalib extended it with panoramas that need not be aligned with gravity
321
+ ([AnyCalib: Extended OpenPano Dataset](https://github.com/javrtg/AnyCalib?tab=readme-ov-file#extended-openpano-dataset));
322
+ the extended version consists of tonemapped panoramas from
323
+ [The Laval Photometric Indoor HDR Dataset](http://hdrdb.com/indoor-hdr-photometric/),
324
+ [PolyHaven](https://polyhaven.com/hdris), [HDRMaps](https://hdrmaps.com/freebies/free-hdris/),
325
+ [AmbientCG](https://ambientcg.com/list?type=hdri&sort=popular) and
326
+ [BlenderKit](https://www.blenderkit.com/asset-gallery?query=category_subtree:hdr). We use AnyCalib's splits.
327
+ - **CommonsPano**: our 360° panoramas from Wikimedia Commons, at
328
+ [LiteCalib/CommonsPano](https://huggingface.co/datasets/LiteCalib/CommonsPano), in two subsets: `by` (public
329
+ domain / CC0 / CC BY) and `by-sa` (CC BY-SA); a per-file attribution list. The released models use both.
330
+ - **MegaScenes** ([megascenes.github.io](https://megascenes.github.io)): real photos from Wikimedia Commons with
331
+ COLMAP reconstructions; each photo keeps its Commons licence.
332
+
333
+ We thank the authors of [The Laval Photometric Indoor HDR Dataset](http://hdrdb.com/indoor-hdr-photometric/) for
334
+ allowing us to release the weights of LiteCalib under the Apache License 2.0, and the authors of all the datasets
335
+ above for making their images freely available.
336
+
337
+ The benchmarks used for evaluation are AnyCalib's (downloaded from their original sources by
338
+ `eval/download_benchmarks.py`), plus InFlux / InFlux++ ([InFlux](https://github.com/princeton-vl/InFlux), CC BY 4.0)
339
+ and ScanNet++ (its own terms of use).
340
+
341
+ ## License and acknowledgements
342
+
343
+ LiteCalib is released under the Apache License 2.0. It builds on [AnyCalib](https://github.com/javrtg/AnyCalib)
344
+ (Apache 2.0): its camera models, calibrator, DPT decoder and vendored DINOv2 are included in
345
+ `litecalib/anycalib/`, and `litecalib/calibrator_{cpu,cuda}.py` port its calibrator to Numba (see `NOTICE`).
346
+ The backbones are [DINOv2](https://github.com/facebookresearch/dinov2) (Apache 2.0).
347
+
348
+ The released weights are also under the Apache License 2.0 (see [Datasets](#datasets) for the permission this
349
+ relies on).
350
+
351
+ ## Citation
352
+
353
+ The paper is under review; a citation will be added here.