Python
Need help with MegaDepth?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
zhengqili

Description

Code of single-view depth prediction algorithm on Internet Photos described in "MegaDepth: Learning Single-View Depth Prediction from Internet Photos, Z. Li and N. Snavely, CVPR 2018".

469 Stars 127 Forks MIT License 24 Commits 32 Opened issues

Services available

Need anything else?

MegaDepth: Learning Single-View Depth Prediction from Internet Photos

This is a code of the algorithm described in "MegaDepth: Learning Single-View Depth Prediction from Internet Photos, Z. Li and N. Snavely, CVPR 2018". The code skeleton is based on "https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix". If you use our code or models for academic purposes, please consider citing:

@inproceedings{MDLi18,
    title={MegaDepth: Learning Single-View Depth Prediction from Internet Photos},
    author={Zhengqi Li and Noah Snavely},
    booktitle={Computer Vision and Pattern Recognition (CVPR)},
    year={2018}
}

Examples of single-view depth predictions on the photos we randomly downloaded from Internet:

Dependencies:

  • The code was written in Pytorch 0.2 and Python 2.7, but it should be easy to adapt it to Python 3 and latest Pytorch version if needed.
  • You might need skimage, h5py libraries installed for python before running the code.

Single-view depth prediction on any Internet photo:

  • Download pretrained models from: http://www.cs.cornell.edu/projects/megadepth/dataset/models/bestgeneralizationnetG.pth and put it in "checkpoints/testlocal/bestgeneralizationnet_G.pth
  • In python file "models/HGmodel.py", in init function, change to "modelparameters = self.loadnetwork(model, 'G', 'bestgeneralization')"
  • run demo code
    bash
    python demo.py
    
    You should see an inverse depth prediction saved as demo.png from an original photo demo.jpg. If you want to use RGB maps for visualization, like the figures in our paper, you have to install/run semantic segmentation from https://github.com/kazuto1011/pspnet-pytorch trained on ADE20K to mask out sky, because inconsistent depth prediction of unmasked sky will not make RGB visualization resonable.

Evaluation on the MegaDepth test splits:

  • Download MegaDepth V1 dataset from project website: http://www.cs.cornell.edu/projects/megadepth/.
  • Download pretrained model (specific for MD dataset) from http://www.cs.cornell.edu/projects/megadepth/dataset/models/bestvanilanetG.pth and put it in "checkpoints/testlocal/bestvanilanet_G.pth"
  • Updated: You might also consider downloading extra 4 pretrained models from (See README and our website for explanations): http://www.cs.cornell.edu/projects/megadepth/dataset/models/testmodel1_4.zip
  • Download test list files from http://www.cs.cornell.edu/projects/megadepth/dataset/datalists/testlists.tar.gz, it should include two folders corresponding to images with landscape and portrait orientations.
  • Download precomputed sparse features from http://www.cs.cornell.edu/projects/megadepth/dataset/Megadepthv1/sparsefeatures.zip
  • To compute scale invarance RMSE on MD testset, change the variable "datasetroot" in python file "rmseerrormain.py" to the root directory of MegaDepthv1 folder, and change variable "testlistdirl" and "testlistdirp" to corresponding folder paths of test lists, and run:
    bash
    python rmse_error_main.py
    
  • To compute Structure from Motion Disagreement Rate (SDR), change the variable "datasetroot" in python file "rmseerrormain.py" to the root directory of MegaDepthv1 folder, and change variable "testlistdirl" and "testlistdirp" to corresponding folder paths of test lists, and run:
    bash
    python SDR_compute.py
    
  • If you want to run our model on arbitrary Internet photos, please download pretrained model from http://www.cs.cornell.edu/projects/megadepth/dataset/models/bestgeneralizationnet_G.pth, which has much better generalization ability to completely unknown scenes (Note: for clarification, this model is used for more general purpose. We trained the network on top of DIW pretrained weights. It may have better performance than what was described in the paper, if you want to compare yours with our method, you might use the models: http://www.cs.cornell.edu/projects/megadepth/).

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.