Project for UCSD MATH 157, Spring 2026
The FishSense project was created at UC San Diego's Engineers for Exploration as an effort to bring the data collection of fish population analytics to citizen scientists. To accurate measure a fish under water, extensive equipment of exceeding high cost is needed, which is unrealistic in many circumstances. FishSense changes this by utilizing the parallax effect to take accurate measurements with a single commercially available under water camera and laser, which lowers the cost of entry exponentially.
However, this system still needs extensive human input as the laser needs to be manually calibrated with the camera. Secondly, although lasers under water forms a uniform gaussian distribution, harsh conditions means it is currently impossible to get an accurate labeling of the laser reliably, and so human labelers have to come in and verify or correct the labels manually. There is also a problem with extensive underwater ROV deployments where it would be impossible to calibrate the laser and thus cannot retrieve accurate readings.
To fix this, the Monocular Depth project was created, in which we try to create a differentiable underwater renderer that can render physically accurate path-traced underwater scenes in the forward path, and using these median functions render an existing image under water to get the scene data, and thus the metric depth data, in which we can know the length of the fish. This will allow use to utilize essentially any under water image and retrieve accurate data without manual efforts, enabling anyone with a camera to be a citizen scientist.
Currently, the state-of-the-art reverse-rendering software is Mitsuba 3, however this renderer presents a few issues with underwater images that all relate to the accuracy of IEEE 754 single-precision floating point 32 operations and the need for higher accuracy floating point 64 operations.
The current most accurate underwater color correction and image formation model is Sea-thru from the University of Haifa, in which many light interaction functions involve exceedingly small floating point numbers. This can be seen in the equations from the supporting document, A Revised Underwater Image Formation Model.
We can see many cases where we involve very small values for
This is an issue with Mitsuba 3 as renderer uses Nvidia's OptiX platform for path-tracing, which has no support for the floating point 64 datatype outright. The CUDA implementation does have support, however it is exceedingly slow, and this is compounded by the fact that modern Nvidia GPUs in not only the consumer space, but also the workstation space have reduced fp64 throughput in favor of increasing lower accuracy fp16 and fp8 performance for machine learning use cases. For example, a RTX PRO 6000 Blackwell, the fastest Nvidia GPU available for purchase has a 64 times penalty in FP64 performance, which makes it on par with a Quadro K6000 from 2013. This means that we either have to figure out if there is some mathematical operations that we can do to solve this inaccuracy, or we have to build something else from the ground up to support AMD GPUs that do not have this same issue
The goal of this project is to find a way to mathematically reduce numerical stability issue of underwater
image formation functions and formulate the proof in LEAN, or a proof in LEAN that an adequate amount of
techniques fail to do this, and therefore determine if it is possible to use floating point 32 for the
project.
Because of limitations with available LEAN techniques, we will not be looking into the exact error bounds for FP32 and FP64 operations, but instead try to find a way to re-write the formation models so:
- The functions are proven to be mathematically equivalent to the original
- Contain as few places where numerical stability issues can occur
- Optionally have good performance, although the verification of this is outside the scope for the project
Thus, we are here using the assumption that FP32 is sufficient for
Specifically, we try to prove that there is a way to rewrite the following functions so that they are stable:
Backscatter:
Veiling Light (Backscatter as
My first approach is using the classic log sum trick. Consider the following softmax function commonly used in machine learning:
Softmax for a vector
If some
However, Adding or subtracting the same constant from every element does not change the softmax result:
Therefore, if we have
Then the largest exponent becomes
The stable softmax becomes:
However, I realized that this is not the correct approach, as we are mostly likely dealing with a
cancellation problem rather than an overflow problem. For example, in backscatter we have
Many modern programming languages, including CUDA, have a expm1 function for very small numbers (in CUDA,
this function for FP32 numbers is expm1f()). This function executes the operation expm1(x)
i.e:
And therefore, by utilizing this, we can approach the project in generally 3 steps:
-
Prove that the taylor series for
expm1is exact -
Rewrite the identified formulation models using
expm1so that they are stable -
Prove that the stable version of the functions are equivalent to the original
This is possible because LEAN strictly enforces abstraction boundaries, which means that a theorem once proven is presumed to be true, and you can use it in a further proof that satisfies the condition, but the elements inside the theorems are contained and cannot be accessed by this further proof.
To a degree, I was able to rewrite the identified functions with expm1 and other supporting definitions that stem from it, and using LEAN proved that the rewrites are the equivalent of original functions.
Specifically, the LEAN code can be found in this GitHub repository, with an included README that explains every definition and the theorems that prove their equality.
The project does not currently prove:
- FP32 error bounds
- FP64 error bounds
- IEEE-754 correctness
Those require a separate formal floating-point semantics and are outside the scope of this project
There are also lone
Because expm1 is based on an infinite taylor series, it may require significant compute resources to run.
This may be very computationally expensive, and may be even slower than taking the 64 times performance
penalty on modern Nvidia graphics cards.
However, this is beyond the scope of this project, and a future project benchmarking the performance implication is needed to answer this question
| Variable | Description |
|---|---|
| wavelength | |
| beam absorption coefficient | |
| beam scattering coefficient | |
| beam attenuation coefficient: |
|
| diffuse downwelling attenuation coefficient | |
| irradiance | |
| radiance | |
| luminance | |
| sensor spectral response | |
| reflectance | |
| veiling light | |
| color channels R,G,B | |
| wideband attenuation coefficient | |
| wideband veiling light | |
| RGB image with attenuated signal | |
| RGB image with unattenuated signal | |
| depth (vertical range) | |
| range along LOS | |
| direction in 3-space | |
| backscattered light | |
| direct transmitted light | |
| forward scattered light | |
| AOP | apparent optical properties |
| IOP | inherent optical properties |
| LOS | line of sight |
| RTE | radiance transfer equation |
| VSF | volume scattering function |
PhD Student Christopher L. Crutchfield from the Electrical and Computer Engineering department at UCSD laid the groundwork with the FishSense project and some ideas for Monocular Depth.
Because this is an AI-open course, I utilized Google Gemini to generate some documentation for the project, as well as try to complete theorems that are too hard to tackle by hand and suggesting on intermediate approach methods to some problems. This would not have an impact on the results of this project as LEAN checks strictly on mathematical theorems. I also used LLM to do some busywork like converting an equation into LaTeX, markdown, etc.
No LLM was used to write this paper.
Akkaynak, Derya, et al. “What Is the Space of Attenuation Coefficients in Underwater Computer Vision?” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017, pp. 4931–4940. IEEE, https://doi.org/10.1109/CVPR.2017.68.
Akkaynak, Derya, and Tali Treibitz. “A Revised Underwater Image Formation Model.” Proceedings of the IEEE/ CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2018, pp. 6723–6732. IEEE, https://doi.org/10.1109/CVPR.2018.00703.
Akkaynak, Derya, and Tali Treibitz. “Sea-Thru: A Method for Removing Water From Underwater Images.” Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2019, pp. 1682–1691. IEEE, https://doi.org/10.1109/CVPR.2019.00178.
Nimier-David, Merlin, et al. “Mitsuba 2: A Retargetable Forward and Inverse Renderer.” ACM Transactions on Graphics, vol. 38, no. 6, 2019, article 203, pp. 1–17. Association for Computing Machinery, https://doi.org/10.1145/3355089.3356498.