https://github.com/nandometzger/mlfocallengths
Estimating the Focal Length from Monocular Images
https://github.com/nandometzger/mlfocallengths
cnn computer-vision deep-learning
Last synced: 12 months ago
JSON representation
Estimating the Focal Length from Monocular Images
- Host: GitHub
- URL: https://github.com/nandometzger/mlfocallengths
- Owner: nandometzger
- Created: 2022-12-30T14:12:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T06:23:17.000Z (almost 2 years ago)
- Last Synced: 2024-08-02T07:36:13.778Z (almost 2 years ago)
- Topics: cnn, computer-vision, deep-learning
- Language: Python
- Homepage:
- Size: 36.7 MB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MLFocalLengths: Estimating the Focal Length of a Single Image
Information about the focal length with which a photo is taken might be obstructed (internet photos) or not available (vintage photos). Inferring the focal length of a photo solely from a monocular view is an ill-posed task that requires knowledge about the scale of objects and their distance to the camera - e.g. scene understanding. I trained a deep learning model to acquire such scene understanding to predict the focal length and open-source the model with this repository.

Focal lengths influence the distortion of an image.
Source image credits to Reddit user [u/scyshc](https://www.reddit.com/r/photography/comments/48l8uy/a_gif_showing_why_focal_length_matters/)
# Method
I preprocessed the focal lengths of ~15k of my personal image database to convert them to 35mm equivalent using [Jeffrey Friedl's LR Plugin](http://regex.info/blog/lightroom-goodies/focal-length-sort). The images were cropped to a square shape and resampled to 256x256. Using that data, I trained an EfficientNet B4 with log-transformed labels and L1 loss, which showed a mean absolute error of 16mm on the hold-out set.
# Reproducability
Set up a python environment using ``requirements.txt``. Commands for the creation of the dataset, training, and prediction are provided in the [lauch.json file](https://github.com/nandometzger/MLFocalLengths/blob/main/.vscode/launch.json).
Training data is available upon request.
The pretrained model can be accessed [here](https://drive.google.com/file/d/16Yf8dQrIAg-k8RKcy_chRsctrhQ4yzse/view?usp=share_link).
# Citation
```
@misc{Metzger2023MLFocalLengths,
author = {Nando Metzger},
title = {MLFocalLengths: Estimating the Focal Length of a Single Image},
year = {2023},
url = {https://github.com/nandometzger/MLFocalLengths},
note = {GitHub repository}
}
```