Home

Awesome

MonoViT

This is the reference PyTorch implementation for training and testing depth estimation models using the method described in

MonoViT: Self-Supervised Monocular Depth Estimation with a Vision Transformer arxiv

Chaoqiang Zhao*, Youmin Zhang*, Matteo Poggi, Fabio Tosi, Xianda Guo,Zheng Zhu, Guan Huang, Yang Tang, Stefano Mattoccia

PWC

<div class='paper-box'><div class='paper-box-image'><img src='fig/kittiandds.png' alt="sym" width="90%"></div> <div class='paper-box-text' markdown="1">

If you find our work useful in your research please consider citing our paper:

@inproceedings{monovit,
  title={MonoViT: Self-Supervised Monocular Depth Estimation with a Vision Transformer},
  author={Zhao, Chaoqiang and Zhang, Youmin and Poggi, Matteo and Tosi, Fabio and Guo, Xianda and Zhu, Zheng and Huang, Guan and Tang, Yang and Mattoccia, Stefano},
  booktitle={International Conference on 3D Vision},
  year={2022}
}

⚙️ Setup

Assuming a fresh Anaconda distribution, you can install the dependencies with:

pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0
pip install dominate==2.4.0 Pillow==6.1.0 visdom==0.1.8
pip install tensorboardX==1.4 opencv-python  matplotlib scikit-image
pip3 install mmcv-full==1.3.0 mmsegmentation==0.11.0  
pip install timm einops IPython

We ran our experiments with PyTorch 1.9.0, CUDA 11.1, Python 3.7 and Ubuntu 18.04.

Note that our code is built based on Monodepth2

Results on KITTI

We provide the following options for --model_name:

--model_nameTraining modalityPretrained?Model resolutionAbs RelSq RelRMSERMSE logdelta < 1.25delta < 1.25^2delta < 1.25^3
mono_640x192MonoYes640 x 1920.0990.7084.3720.1750.9000.9670.984
mono+stereo_640x192Mono + StereoYes640 x 1920.0980.6834.3330.1740.9040.9670.984
mono_1024x320MonoYes1024 x 3200.0960.7144.2920.1720.9080.9680.984
mono+stereo_1024x320Mono + StereoYes1024 x 3200.0930.6714.2020.1690.9120.9690.985
mono_1280x384MonoYes1280 x 3840.0940.6824.2000.1700.9120.9690.984

Robustness

ModelModalitymCE (%)mRR (%)CleanBrightDarkFogFrostSnowContrastDefocusGlassMotionZoomElasticQuantGaussianImpulseShotISOPixelateJPEG
MonoDepth2<sub>R18</sub>Mono100.0084.460.1190.1300.2800.1550.2770.5110.1870.2440.2420.2160.2010.1290.1930.3840.3890.3400.3880.1450.196
MonoDepth2<sub>R18+nopt</sub>Mono119.7582.500.1440.1830.3430.3110.3120.3990.4160.2540.2320.1990.2070.1480.2120.4410.4520.4020.4530.1530.171
MonoDepth2<sub>R18+HR</sub>Mono106.0682.440.1140.1290.3760.1550.2710.5820.2140.3930.2570.2300.2320.1230.2150.3260.3520.3170.3440.1380.198
MonoDepth2<sub>R50</sub>Mono113.4380.590.1170.1270.2940.1550.2870.4920.2330.4270.3920.2770.2080.1300.1980.4090.4030.3680.4250.1550.211
MaskOccMono104.0582.970.1170.1300.2850.1540.2830.4920.2000.3180.2950.2280.2010.1290.1840.4030.4100.3640.4170.1430.177
DNet<sub>R18</sub>Mono104.7183.340.1180.1280.2640.1560.3170.5040.2090.3480.3200.2420.2150.1310.1890.3620.3660.3260.3570.1450.190
CADepthMono110.1180.070.1080.1210.3000.1420.3240.5290.1930.3560.3470.2850.2080.1210.1920.4230.4330.3830.4480.1440.195
HR-DepthMono103.7382.930.1120.1210.2890.1510.2790.4810.2130.3560.3000.2630.2240.1240.1870.3630.3730.3360.3740.1350.176
DIFFNet<sub>HRNet</sub>Mono94.9685.410.1020.1110.2220.1310.1990.3520.1610.5130.3300.2800.1970.1140.1650.2920.2660.2550.2700.1350.202
ManyDepth<sub>single</sub>Mono105.4183.110.1230.1350.2740.1690.2880.4790.2270.2540.2790.2110.1940.1340.1890.4300.4500.3870.4520.1470.182
FSRE-DepthMono99.0583.860.1090.1280.2610.1390.2370.3930.1700.2910.2730.2140.1850.1190.1790.4000.4140.3700.4070.1470.224
MonoViT<sub>MPViT</sub>Mono79.3389.150.0990.1060.2430.1160.2130.2750.1190.1800.2040.1630.1790.1180.1460.3100.2930.2710.2900.1620.154
MonoViT<sub>MPViT+HR</sub>Mono70.7990.670.0900.0970.2210.1130.2170.2530.1130.1460.1590.1440.1750.0980.1380.2670.2460.2360.2460.1350.145

The RoboDepth Challenge Team is evaluating the robustness of different depth estimation algorithms. MonoViT has achieved the outstanding robustness.

💾 KITTI training data

You can download the entire raw KITTI dataset by running:

wget -i splits/kitti_archives_to_download.txt -P kitti_data/

Then unzip with

cd kitti_data
unzip "*.zip"
cd ..

Warning: it weighs about 175GB, so make sure you have enough space to unzip too!

Our default settings expect that you have converted the png images to jpeg with this command, which also deletes the raw KITTI .png files:

find kitti_data/ -name '*.png' | parallel 'convert -quality 92 -sampling-factor 2x2,1x1,1x1 {.}.png {.}.jpg && rm {}'

or you can skip this conversion step and train from raw png files by adding the flag --png when training, at the expense of slower load times.

The above conversion command creates images which match our experiments, where KITTI .png images were converted to .jpg on Ubuntu 16.04 with default chroma subsampling 2x2,1x1,1x1. We found that Ubuntu 18.04 defaults to 2x2,2x2,2x2, which gives different results, hence the explicit parameter in the conversion command.

You can also place the KITTI dataset wherever you like and point towards it with the --data_path flag during training and evaluation.

Splits

The train/test/validation splits are defined in the splits/ folder. By default, the code will train a depth model using Zhou's subset of the standard Eigen split of KITTI, which is designed for monocular training. You can also train a model using the new benchmark split or the odometry split by setting the --split flag.

Custom dataset

You can train on a custom monocular or stereo dataset by writing a new dataloader class which inherits from MonoDataset – see the KITTIDataset class in datasets/kitti_dataset.py for an example.

⏳ Training

PLease download the ImageNet-1K pretrained MPViT model to ./ckpt/.

For training, please download monodepth2, replace the depth network, and revise the setting of the depth network, the optimizer and learning rate according to trainer.py.

Because of the different torch version between MonoViT and Monodepth2, the func transforms.ColorJitter.get_params in dataloader should also be revised to transforms.ColorJitter.

By default models and tensorboard event files are saved to ./tmp/<model_name>. This can be changed with the --log_dir flag.

Monocular training:

python train.py --model_name mono_model --learning_rate 5e-5

Monocular + stereo training:

python train.py --model_name mono+stereo_model --use_stereo --learning_rate 5e-5

GPUs

The code of the Single GPU version can only be run on a single GPU. You can specify which GPU to use with the CUDA_VISIBLE_DEVICES environment variable:

CUDA_VISIBLE_DEVICES=1 python train.py --model_name mono_model

📊 KITTI evaluation

To prepare the ground truth depth maps, please follow the monodepth2.

...assuming that you have placed the KITTI dataset in the default location of ./kitti_data/.

The following example command evaluates the epoch 19 weights of a model named mono_model (Note that please use evaluate_depth.py for 640x192 models and evaluate_hr_depth.py --height 320/384 --width 1024/1280 for the others):

python evaluate_depth.py --load_weights_folder ./tmp/mono_model/models/weights_19/ --eval_mono

An additional parameter --eval_split can be set. The three different values possible for eval_split are explained here:

--eval_splitTest set sizeFor models trained with...Description
eigen697--split eigen_zhou (default) or --split eigen_fullThe standard Eigen test files
eigen_benchmark652--split eigen_zhou (default) or --split eigen_fullEvaluate with the improved ground truth from the new KITTI depth benchmark
benchmark500--split benchmarkThe new KITTI depth benchmark test files.

Contact us

Contact us: zhaocqilc@gmail.com

Acknowledgement

Thanks the authors for their works:

Monodepth2

MPVIT

HR-Depth

DIFFNet