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+
An image geolocation project developed for my Deep Learning course. The model predicts latitude and longitude from a photograph using MobileViTV2, country classification, and geographic cells.
|
| 4 |
+
|
| 5 |
+
The final system achieved a **199.06 km median error on the validation split**, with approximately **4.44 million parameters**.
|
| 6 |
+
|
| 7 |
+
[Try the live demo](https://huggingface.co/spaces/arham061/Image-geolocation-challenge) · [Read the report](submission/report.pdf) · [Explore the notebooks](notebooks/)
|
| 8 |
+
|
| 9 |
+
## Results
|
| 10 |
+
|
| 11 |
+
| Metric | Validation result |
|
| 12 |
+
|---|---:|
|
| 13 |
+
| Median distance error | 199.06 km |
|
| 14 |
+
| Mean distance error | 497.73 km |
|
| 15 |
+
| Predictions within 200 km | 50.04% |
|
| 16 |
+
| Predictions within 750 km | 78.61% |
|
| 17 |
+
|
| 18 |
+
These results are from the validation split used during development. They are not scores on the unlabeled holdout set or a guarantee of accuracy on new uploads.
|
| 19 |
+
|
| 20 |
+
## How it works
|
| 21 |
+
|
| 22 |
+
The model predicts probabilities for 12 countries and 96 geographic cells, with eight cells per country.
|
| 23 |
+
|
| 24 |
+
Each cell's probability is multiplied by the probability of its country. After normalization, the model calculates coordinates as a weighted average of the cell centres.
|
| 25 |
+
|
| 26 |
+
The final prediction uses the same trained model at two input resolutions:
|
| 27 |
+
|
| 28 |
+
- 384 × 384 and 512 × 512 inputs
|
| 29 |
+
- Equal averaging of the two sets of output logits
|
| 30 |
+
- Country temperature of 0.25
|
| 31 |
+
- Cell temperature of 0.75
|
| 32 |
+
|
| 33 |
+
Temperature scaling changes how concentrated the probabilities are before country gating. Both resolutions use the same model weights.
|
| 34 |
+
|
| 35 |
+
## Experiments
|
| 36 |
+
|
| 37 |
+
The notebooks record the development process, including experiments that did not improve the results:
|
| 38 |
+
|
| 39 |
+
- Direct coordinate regression
|
| 40 |
+
- Auxiliary country classification
|
| 41 |
+
- Blending coordinates with country-centre estimates
|
| 42 |
+
- Geographic-cell classification
|
| 43 |
+
- Cell-only fine-tuning
|
| 44 |
+
- Country-gated cells
|
| 45 |
+
- Temperature scaling and gating ablations
|
| 46 |
+
- Balancing the number of training images per cell
|
| 47 |
+
- Higher-resolution training and fine-tuning
|
| 48 |
+
- Combining predictions at two resolutions
|
| 49 |
+
|
| 50 |
+
Increasing the input resolution produced some of the largest later improvements. Balanced cells and additional temperature tuning gave smaller or inconsistent gains.
|
| 51 |
+
|
| 52 |
+
The [report](submission/report.pdf) discusses the experiments and their limitations in more detail.
|
| 53 |
+
|
| 54 |
+
## Run the app locally
|
| 55 |
+
|
| 56 |
+
Clone the repository:
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
git clone https://github.com/arham061/image-geolocation-challenge.git
|
| 60 |
+
cd image-geolocation-challenge
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Create and activate a virtual environment:
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
python -m venv .venv
|
| 67 |
+
source .venv/bin/activate
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
Install the dependencies:
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
python -m pip install -r submission/requirements.txt
|
| 74 |
+
python -m pip install gradio torchvision
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Start the app:
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
python app.py
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Open the local URL printed in the terminal. Upload a photograph to see the predicted country, coordinates, and an OpenStreetMap link.
|
| 84 |
+
|
| 85 |
+
The app uses CUDA when available and otherwise runs on CPU. It expects the exported model files in `submission/model/`.
|
| 86 |
+
|
| 87 |
+
The hosted Hugging Face version includes the additional ZeroGPU integration needed by that hosting environment.
|
| 88 |
+
|
| 89 |
+
## Submission files
|
| 90 |
+
|
| 91 |
+
The `submission/` directory contains:
|
| 92 |
+
|
| 93 |
+
- `model/`: exported weights, model configuration, preprocessing configuration, and inference settings
|
| 94 |
+
- `predict.py`: generates predictions for the holdout images
|
| 95 |
+
- `evaluate.py`: compares predictions with labeled coordinates
|
| 96 |
+
- `train.py`: training code
|
| 97 |
+
- `requirements.txt`: project dependencies
|
| 98 |
+
- `predictions.csv`: generated holdout predictions
|
| 99 |
+
- Report files
|
| 100 |
+
|
| 101 |
+
To run the holdout prediction script from the repository root:
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
python submission/predict.py
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
It expects images in `geo_dataset/holdout_public/` and writes `submission/predictions.csv`.
|
| 108 |
+
|
| 109 |
+
To evaluate predictions against a corresponding labels file:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
python submission/evaluate.py \
|
| 113 |
+
--labels path/to/labels.csv \
|
| 114 |
+
--predictions path/to/predictions.csv
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
The labels CSV must contain `filename`, `lat`, and `lng`. The predictions CSV must contain `filename`, `pred_lat`, and `pred_lng`.
|
| 118 |
+
|
| 119 |
+
The dataset is not included in this repository.
|
| 120 |
+
|
| 121 |
+
## Limitations
|
| 122 |
+
|
| 123 |
+
The model was trained on images from Belarus, Finland, France, Germany, Iceland, Italy, Norway, Poland, Spain, Sweden, Turkey, and the United Kingdom.
|
| 124 |
+
|
| 125 |
+
It will still produce coordinates for images from other countries, but those predictions should not be considered reliable. Images with few geographic clues or different subjects and framing from the training data can also produce large errors.
|
| 126 |
+
|
| 127 |
+
The predicted country and final coordinates may disagree because the coordinates are averaged across multiple cell centres.
|
| 128 |
+
|
| 129 |
+
The validation split was used repeatedly to select experiments and inference settings, so the reported result may be optimistic compared with performance on unseen data.
|
| 130 |
+
|
| 131 |
+
## Training hardware
|
| 132 |
+
|
| 133 |
+
Training used an NVIDIA RTX 4000 Ada Generation GPU with approximately 20 GB of VRAM.
|
| 134 |
+
|
| 135 |
+
## Acknowledgements
|
| 136 |
+
|
| 137 |
+
The backbone is Apple's pretrained [MobileViTV2 model](https://huggingface.co/apple/mobilevitv2-1.0-imagenet1k-256), used through Hugging Face Transformers.
|
| 138 |
+
|
| 139 |
+
The demo uses Gradio and is hosted on Hugging Face Spaces. References and further methodological details are included in the report.
|
| 140 |
+
|
| 141 |
+
## License
|
| 142 |
+
|
| 143 |
+
See [LICENSE](LICENSE).
|