Giter Site home page Giter Site logo

tibhannover / geoestimation Goto Github PK

View Code? Open in Web Editor NEW
125.0 8.0 31.0 1.88 MB

This repository contains all necessary meta information, results and source files to reproduce the results in the publication Eric Müller-Budack, Kader Pustu-Iren, Ralph Ewerth: "Geolocation Estimation of Photos using a Hierarchical Model and Scene Classification", In: European Conference on Computer Vision (ECCV), Munich, 2018.

Home Page: https://labs.tib.eu/geoestimation

License: GNU General Public License v3.0

HTML 14.97% JavaScript 15.96% Python 69.08%
geolocalization deep-learning scene-classification geolocation-estimation pytorch

geoestimation's Introduction

Geolocation Estimation of Photos using a Hierarchical Model and Scene Classification

Conference

This is the official GitHub page for the paper (Link):

Eric Müller-Budack, Kader Pustu-Iren, Ralph Ewerth: "Geolocation Estimation of Photos using a Hierarchical Model and Scene Classification". In: European Conference on Computer Vision (ECCV), Munich, Springer, 2018, 575-592.

News

12th December 2020 - PyTorch version: We release a PyTorch implementation and provide weights of a pre-trained base(M, f*) model with underlying ResNet50 architecture.

17th February 2020 - original_tf branch: Since our code is not compatible with TensorFlow 2 and relies on a Caffe model for scene classification, we have added a Dockerfile to simplify the installation. In addition, we have modified the inference script. It is now able to automatically generate the reported results in the paper for the testing datasets.

Contents

  • Web Demo
  • Reproduce Paper Results: A seperate branch (original_tf() where all information and pre-trained models are provided to reproduce the original results of the paper.
  • PyTorch Implementation: A re-implemented version of the base(M, f*) model in PyTorch including code for training, validation, testing, and inference.
  • Citation
  • License

Demo

A graphical demonstration where you can compete against the deep learning approach presented in the publication can be found on: https://labs.tib.eu/geoestimation

This demo additionally supports uploading and analyzing your own images. A simplified offline version is located in this repository: https://tibhannover.github.io/GeoEstimation/

Reproduce Paper Results

We provide the original TensorFlow 1.14 implementation based on a ResNet101 to reproduce the results reported in the paper in the original_tf branch.

PyTorch Implementation

We have updated our code in PyTorch including scripts for training, inference and test. We have retrained the base(M, f*) model using a ResNet50 architecture and it achieved comparable results despite its lower complexity.

Contents

Inference

To use the pre-trained model by default, first download the model checkpoint by running:

mkdir -p models/base_M
wget https://github.com/TIBHannover/GeoEstimation/releases/download/pytorch/epoch.014-val_loss.18.4833.ckpt -O models/base_M/epoch=014-val_loss=18.4833.ckpt
wget https://github.com/TIBHannover/GeoEstimation/releases/download/pytorch/hparams.yaml -O models/base_M/hparams.yaml

Inference with pre-trained model:

python -m classification.inference --image_dir resources/images/im2gps/

Available argparse parameter:

--checkpoint CHECKPOINT
    Checkpoint to already trained model (*.ckpt)
--hparams HPARAMS     
    Path to hparams file (*.yaml) generated during training
--image_dir IMAGE_DIR
    Folder containing images. Supported file extensions: (*.jpg, *.jpeg, *.png)
--gpu                 
    Use GPU for inference if CUDA is available, default to true
--batch_size BATCH_SIZE
--num_workers NUM_WORKERS
    Number of workers for image loading and pre-processing

Example output that is also stored in a CSV file:

img_id                                             p_key      pred_class  pred_lat   pred_lng 
Tokyo_00070_439717934_3d0fd200f1_180_97324495@N00  hierarchy  5367        41.4902    -81.7032
429881745_35a951f032_187_37718182@N00              hierarchy  8009        37.1770    -3.5877
104123223_7410c654ba_19_19355699@N00               hierarchy  7284        32.7337    -117.1520

Reproduce Results

Test on Already Trained Model

The (list of) image files for testing can be found on the following links:

Download and extract the two testsets (Im2GPS, Im2GPS3k) in resources/images/<dataset_name> and run the evaluation script with the provided meta data, i.e., the ground-truth coordinate for each image. When using the default paramters, make sure that the pre-trained model is available.

# download im2gps testset
mkdir resources/images/im2gps
wget http://graphics.cs.cmu.edu/projects/im2gps/gps_query_imgs.zip -O resources/images/im2gps.zip
unzip resources/images/im2gps.zip -d resources/images/im2gps/

wget https://raw.githubusercontent.com/TIBHannover/GeoEstimation/original_tf/meta/im2gps_places365.csv -O resources/images/im2gps_places365.csv
wget https://raw.githubusercontent.com/TIBHannover/GeoEstimation/original_tf/meta/im2gps3k_places365.csv -O resources/images/im2gps3k_places365.csv
python -m classification.test

Available argparse paramters:

--checkpoint CHECKPOINT
    Checkpoint to already trained model (*.ckpt)
--hparams HPARAMS     
    Path to hparams file (*.yaml) generated during training
--image_dirs IMAGE_DIRS [IMAGE_DIRS ...]
    Whitespace separated list of image folders to evaluate
--meta_files META_FILES [META_FILES ...]
    Whitespace separated list of respective meta data (ground-truth GPS positions). Required columns: IMG_ID,LAT,LON
--gpu
    Use GPU for inference if CUDA is available, default to True
--precision PRECISION
    Full precision (32), half precision (16)
--batch_size BATCH_SIZE
--num_workers NUM_WORKERS
    Number of workers for image loading and pre-processing

Results on the Im2GPS and Im2GPS3k test sets: The reported accuracies (in percentage) is the fraction of images localized within the given radius (in km) using the GCD distance. Note, that we used the full MP-16 training dataset and all 25600 images for validation, thus the results will differ when not all images are available.

Im2GPS:

Model 1 25 200 750 2500
base(M, c) 9.3 31.6 49.8 67.1 78.9
base(M, m) 13.9 34.6 48.1 68.4 79.3
base(M, f) 15.6 39.2 48.9 65.8 78.5
base(M, f*) 14.8 37.6 48.9 68.4 78.9
base(M, f*) (original) 15.2 40.9 51.5 65.4 78.5

Im2GPS3k:

Model 1 25 200 750 2500
base(M, c) 6.2 24.3 36.3 51.7 67.0
base(M, m) 8.3 26.2 35.7 51.4 66.5
base(M, f) 9.9 27.3 36.2 51.2 66.4
base(M, f*) 10.1 28.0 36.9 51.1 67.0
base(M, f*) (original) 9.7 27.0 35.6 49.2 66.0
ISN(M, f*, S3) (original) 10.5 28.0 36.6 49.7 66.0

Training from Scratch

We provide a complete training script which is written in PyTorch Lightning and report all hyper-paramters used for the provided model. Furthermore, a script is given to download and pre-process the images that are used for training and validiation.

  1. Download training and validation images
    • We provide a script to download the images given a list of URLs
    • Due to no longer publicly available images, the size of the dataset might be smaller than the original.
    • We also store the images in chunks using MessagePack to speed-up the training process (similar to multiple TFRecord files)
  2. Given multiple s2 partitionings (e.g. coarse, middle, fine from the paper), the respective classes are assigned to each image on both datasets.
  3. Training and hyper-paramters: All hyper-paramters can be configured in configs/baseM.yml as well as paramters from PyTorch Lightning Trainer class.

Necessary steps:

# download and preprocess images
wget https://github.com/TIBHannover/GeoEstimation/releases/download/v1.0/mp16_urls.csv -O resources/mp16_urls.csv
wget https://github.com/TIBHannover/GeoEstimation/releases/download/pytorch/yfcc25600_urls.csv -O resources/yfcc25600_urls.csv 
python download_images.py --output resources/images/mp16 --url_csv resources/mp16_urls.csv --shuffle
python download_images.py --output resources/images/yfcc25600 --url_csv resources/yfcc25600_urls.csv --shuffle --size_suffix ""

# assign cell(s) for each image using the original meta information
wget https://github.com/TIBHannover/GeoEstimation/releases/download/v1.0/mp16_places365.csv -O resources/mp16_places365.csv
wget https://github.com/TIBHannover/GeoEstimation/releases/download/pytorch/yfcc25600_places365.csv -O resources/yfcc25600_places365.csv
python partitioning/assign_classes.py
# remove images that were not downloaded 
python filter_by_downloaded_images.py

# train geo model from scratch
python -m classification.train_base --config config/baseM.yml

Geographical S2 Cell Partitioning

The geographical cell labels are extracted using the S2 geometry library and can be visualized on http://s2.sidewalklabs.com/regioncoverer/. Create a partitioning using the following command for a given dataset (as CSV file) which contains an image id, latitude and longitude. We provide the partitionings that are used in the paper below.

python partitioning/create_cells.py [-h] [-v] --dataset DATASET --output OUTPUT --img_min IMG_MIN --img_max IMG_MAX [--lvl_min LVL_MIN]
                       [--lvl_max LVL_MAX]
# Optional arguments:
#   -h, --help         show this help message and exit
#   -v, --verbose      verbose output
#   --dataset DATASET  Path to dataset csv file
#   --output OUTPUT    Path to output directory
#   --img_min IMG_MIN  Minimum number of images per geographical cell
#   --img_max IMG_MAX  Maximum number of images per geographical cell
#   --lvl_min LVL_MIN  Minimum partitioning level (default = 2)
#   --lvl_max LVL_MAX  Maximum partitioning level (default = 30)
#   --column_img_path  CSV input column name for image id / path
#   --column_lat       CSV input column name latitude
#   --column_lng       CSV input column name longitude

Requirements

All requirements are listed in the environment.yml. We recomment to use conda to install all required packages in an individual environment.

# clone this repo
git clone https://github.com/TIBHannover/GeoEstimation.git && cd GeoEstimation
# install dependencies
conda env create -f environment.yml 
conda activate geoestimation-github-pytorch
# download pre-calculated parititonings
mkdir -p resources/s2_cells
wget https://raw.githubusercontent.com/TIBHannover/GeoEstimation/original_tf/geo-cells/cells_50_5000.csv -O resources/s2_cells/cells_50_5000.csv
wget https://raw.githubusercontent.com/TIBHannover/GeoEstimation/original_tf/geo-cells/cells_50_2000.csv -O resources/s2_cells/cells_50_2000.csv
wget https://raw.githubusercontent.com/TIBHannover/GeoEstimation/original_tf/geo-cells/cells_50_1000.csv -O resources/s2_cells/cells_50_1000.csv

Citation

@inproceedings{muller2018geolocation,
  author    = {Müller-Budack, Eric and Pustu-Iren, Kader and Ewerth, Ralph},
  title     = {Geolocation Estimation of Photos Using a Hierarchical Model and Scene
               Classification},
  booktitle = {Computer Vision - {ECCV} 2018 - 15th European Conference, Munich,
               Germany, September 8-14, 2018, Proceedings, Part {XII}},
  series    = {Lecture Notes in Computer Science},
  volume    = {11216},
  pages     = {575--592},
  publisher = {Springer},
  year      = {2018},
  url       = {https://doi.org/10.1007/978-3-030-01258-8\_35},
  doi       = {10.1007/978-3-030-01258-8\_35},
}

Licence

This work is published under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. For details please check the LICENSE file in the repository.

geoestimation's People

Contributors

gmberton avatar jtheiner avatar katrinleinweber avatar pircdef avatar springsteinm avatar tib-visual-analytics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geoestimation's Issues

caffe gpu installation for docker

Hi, noticed that the provided Dockerfile doesn't have caffe for gpu (only for cpu). May I know if you guys have an optimal / preferred way of installing both tf and caffe for a gpu-enabled docker? I had this issue previously where I ended up with very large docker images (9++Gb). Thanks!

Problem downloading the images in mp16 and yfcc25600 datasets

Hi,

When I run these two commands

python download_images.py --output resources/images/mp16 --url_csv resources/mp16_urls.csv --shuffle
python download_images.py --output resources/images/yfcc25600 --url_csv resources/yfcc25600_urls.csv --shuffle --size_suffix ""

the images won't be downloaded. Instead, I can see many HTTP 404 errors in the output.

The output for the first command is like this:

python download_images.py --output resources/images/mp16 --url_csv resources/mp16_urls.csv --shuffle
2022-06-29 15:53:30,045 - ImageDownloader - INFO - Read dataset
2022-06-29 15:53:33,770 - ImageDownloader - INFO - Shuffle images
2022-06-29 15:53:34,081 - ImageDownloader - INFO - Number of URLs: 4723695
2022-06-29 15:53:34,568 - ImageDownloader - ERROR - e1/55/4763369508.jpg : http://farm5.staticflickr.com/4114/4763369508_04516bfd21_z.jpg: 410
2022-06-29 15:53:34,754 - ImageDownloader - ERROR - c8/90/5346653125.jpg : http://farm6.staticflickr.com/5126/5346653125_708d3768b4_z.jpg: 404
2022-06-29 15:53:34,962 - ImageDownloader - ERROR - 47/91/161168280.jpg : http://farm1.staticflickr.com/72/161168280_da7a6c20f2_z.jpg: 404
2022-06-29 15:53:34,989 - ImageDownloader - INFO - 0: 1355.05 image/s
2022-06-29 15:53:36,192 - ImageDownloader - ERROR - 3d/6d/3522933090.jpg : http://farm4.staticflickr.com/3409/3522933090_4d1c7019d0_z.jpg: 404
2022-06-29 15:53:36,193 - ImageDownloader - ERROR - 0f/b2/4461400076.jpg : http://farm5.staticflickr.com/4048/4461400076_b82b6b8b64_z.jpg: 404
2022-06-29 15:53:36,353 - ImageDownloader - ERROR - 0b/01/5288987489.jpg : http://farm6.staticflickr.com/5243/5288987489_b36a013c35_z.jpg: 410
2022-06-29 15:53:36,806 - ImageDownloader - ERROR - e6/63/4872871713.jpg : http://farm5.staticflickr.com/4141/4872871713_80d0900208_z.jpg: 404
2022-06-29 15:53:37,081 - ImageDownloader - ERROR - ac/da/4901883261.jpg : http://farm5.staticflickr.com/4140/4901883261_2965134cce_z.jpg: 404
2022-06-29 15:53:37,105 - ImageDownloader - ERROR - 56/49/2430715106.jpg : http://farm4.staticflickr.com/3069/2430715106_57559920df_z.jpg: 410
2022-06-29 15:53:37,137 - ImageDownloader - ERROR - 3f/d1/8583886682.jpg : http://farm9.staticflickr.com/8100/8583886682_ebd20fcfa0_z.jpg: 404
2022-06-29 15:53:37,307 - ImageDownloader - ERROR - 9e/29/5218438398.jpg : http://farm5.staticflickr.com/4130/5218438398_61cb6e62f1_z.jpg: 404
2022-06-29 15:53:37,532 - ImageDownloader - ERROR - 43/8d/2120188484.jpg : http://farm3.staticflickr.com/2287/2120188484_df2e0610cb_z.jpg: 404

Any suggestion on how to fix the problem?

Thank you for sharing the material for your research, BTW.

AttributeError: can't set attribute 'hparams'

Hi folks,

I came across an AttributeError when I tried to test the pre-trained model. The error always exists even when I downgrade the Pytorch Lightning from 2.1.2 to 1.5 one by one. When it's downgraded to 1.4, an ImportError came out: cannot import name 'get_num_classes from 'torchmetrics.utilities.data''. Then I downgraded the torchmetrics from 0.11.4 to 0.6.0, then the same AttributeError came out again.
I would appreciate any help to solve these problems. Thanks for your attention!
The following is a screenshot of the AttributeError:
image

The following is a screenshot of the ImportError:
image

Update: problem solved! All I need is in the 'environment.yml'.

Web interface upload guess not working

Hello,
Web interface - Trying to upload a photo and guess. After uploading the photo and pressing guess location there’s an “error while calling calc output dict”
Thanks

Align marker & alert colors

Hi! There is currently a mismatch between the markers on the map and the alert box. Red for example denotes the exact opposites, which is a bit confusing:

Since the CSS is loaded externally, I guess we can not simply update those colors, can we? Would it be easiert to change the marker colors to match the CSS?

The gps coordinates along with other image info are saved in the jpeg comment fields. Use Matlab's imfinfo() to read them.

Hi I am running some tests with the model and using the random set. it reports on your http://graphics.cs.cmu.edu/projects/im2gps/ page that the image contains the GPS coordinates in the comments exif field.

Can you help me interpret the data, I am trying to identify if the reported location matches what is in the exif comment.

This is what is reported in 2 randomly selected files
photo: 67787391 c0ab1b285d 25
photo: 97344248 30a4521091 32

Training on Multiple GPUs - IterableDataset

Folks, I have encountered an issue while attempting to run the code on multiple GPUs. I increased the number of GPUs in the Config file and used the distributed backend (DP), but then I encountered errors along the way.

It seems that MsgPackIterableDatasetMultiTargetWithDynLabels(IterableDataset) can not handle multiple GPUs.

If anyone has successfully run the system on multiple GPUs, I would greatly appreciate any guidance or insights you could provide.

Thank you for your attention and assistance.

Best regards

Get hotspot output

Hi, I see from https://labs.tib.eu/geoestimation/ that you can get hotspot outputs from predicted locations.

Is it possible to get that sort of output from either branch in this codebase, or could you point me towards the modifications needed to do so? I can do the GIS side of things, just not sure how to generate that output from torch.

Thanks!

Combining results of hierarchical classifiers

Hi, nice repository and paper. I was wondering, is there are reason multiplication is chosen to combine results of hierarchical classification models? Did you guys by chance test other methods for combining results of hierarchical classifier outputs? It appears from the paper that the classifiers from the more coarse layers are more accurate, so should they be weighted more?

The question regards this line hierarchy_preds = torch.prod(hierarchy_logits, dim=-1) from GeoEstimation.classification.train_base

Can I train on my own dataset and locations?

As expressed in the title, I would like to retrain to get more specific lat-long coordinates on my own dataset (am interested in a smaller geographical area). Would appreciate some help on how to do this if possible, thanks!

Training from scratch pytorch

Hi, Is there another way to train from scratch without using the flickr images or having to download images?
Say using your own set of images on your machine and possibly without shards?

I'm unable to download the flickr images. And would like to train on a smaller subset.
And trying to convert my small dataset of images into message packs causes me to run into issues trying to alter the code.

Thank you.

tf2 branch no scene classification?

Hi, as I recall from the original branch, there is a scene classification step before the geoestimation. In the tf2 branch, is this gone, or integrated into the geoestimation, and what would be the reasoning? Thanks!

Code for Scene Filtering

Thank you for the great repo!
Are you also planning to release the code to compute scene probabilities (scene filtering) for a given image? I'm referring to the module that you mention at Section 3.2 of your paper, which is needed to decide which images are kept or discarded for training.

download links for models doesn't work

Hi there I'm trying to download the models:

  • resnet-v2-101.base_M-keras.h5

as well as trying to find the partitioning cells csv's:
"cells_50_5000.csv",
"cells_50_2000.csv",
"cells_50_1000.csv"

for re-training the model, however the tensorflow model download links direct to "Not Found" and the downloader.py don't work from there.

Appreciate any help.
Thank you

StopIteration Error while training from scratch

Hello,
I have been getting the StopIteration error while training from scratch on custom data. I am using the default parameters provided in the yml file with the cell partitions, message packets of the custom data, and the train and validation mapping of the custom data respectively. I checked how the data is in both the custom and the given dataset in this repo and they are similar. Unsure as to why I am getting this error message.
I have attached a screenshot of my error below:
image

Killed error message?

Hi, I'm trying to run your inference code on a number of images. Some work, but when I add others, I get a "Killed" message and nothing is outputted.

Do you what is going on here?
Thanks.

Could the demo accept user-provided images?

Cool demo, however, what I miss is the possibility to upload my own image to be guessed. Is this not available due to server performance issues or am I missing something?

code can't work

I use pytorch1.10.0, I can't run the code.
train_base.py line21,
self.hparam = hparams

torch.nn.nodules.nodule.py

error: in setattr
object.setattr(self,name,value)
AttributeError: Can't set attribute.

Filtering out fake / cartoon-ish images

Hi, in a project I'm working on, there is a possibility for me to receive images not of actual real scenes e.g. cartoons. They seem to be quite sporadic in terms of geoestimation results, with some producing quite high threshold scores as well. Would there be a recommended way to filter these out? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.