Lightweight stereo matching network based on MobileNetV1 and MobileNetV2

Overview

MobileStereoNet: Towards Lightweight Deep Networks for Stereo Matching

This repository contains the code for

image1 2D-MobileStereoNet prediction image2 Error map
image3 3D-MobileStereoNet prediction image4 Error map

Installation

Requirements

The code is tested on:

  • Ubuntu 18.04
  • Python 3.6
  • PyTorch 1.4.0
  • Torchvision 0.5.0
  • CUDA 10.0

Setting up the environment

conda env create --file mobilestereonet.yml
conda activate mobilestereonet

Training

Set a variable (e.g. DATAPATH) for the dataset directory DATAPATH="/Datasets/SceneFlow/" or DATAPATH="/Datasets/KITTI2015/". Then, you can run the train.py file as below:

Pretraining on SceneFlow

python train.py --dataset sceneflow --datapath $DATAPATH --trainlist ./filenames/sceneflow_train.txt --testlist ./filenames/sceneflow_test.txt --epochs 20 --lrepochs "10,12,14,16:2" --batch_size 8 --test_batch_size 8 --model MSNet2D

Finetuning on KITTI

python train.py --dataset kitti --datapath $DATAPATH --trainlist ./filenames/kitti15_train.txt --testlist ./filenames/kitti15_val.txt --epochs 400 --lrepochs "200:10" --batch_size 8 --test_batch_size 8 --loadckpt ./checkpoints/pretrained.ckpt --model MSNet2D

The arguments in both cases can be set differently depending on the model and the system.

Prediction

The following script creates disparity maps for a specified model:

python prediction.py --datapath $DATAPATH --testlist ./filenames/kitti15_test.txt --loadckpt ./checkpoints/finetuned.ckpt --dataset kitti --colored True --model MSNet2D

Credits

The implementation of this code is based on PSMNet and GwcNet. Also, thanks to Matteo Poggi for the KITTI python utils.

License

Comments
  • Converting pytorch model to torchscript or ONNX format for inference in C++

    Converting pytorch model to torchscript or ONNX format for inference in C++

    Hi @AdrianZw

    Are there any scripts or resources to convert the mobilestereonet to torchscript or ONNX format? I want to use those formats for inference in C++. Any suggestions would be greatly appreciated.

    Thanks.

    opened by nakul3112 9
  • Thank you!  Working to get this running in DepthAI for Embedded Use-Case

    Thank you! Working to get this running in DepthAI for Embedded Use-Case

    Hi there,

    I just wanted to reach out to say that this looks awesome! We make a AI-capable stereo camera ecosystem called DepthAI (Github: https://github.com/luxonis/depthai-hardware) which actually is pretty well tuned to run MobileNetV1- and MobileNetV2- based networks.

    So we are SUPER excited to try to get this running in our ecosystem!

    No real issue here - just wanted to say thanks - and that we'll be working to get this running in DepthAI, issue https://github.com/luxonis/depthai/issues/476.

    -Brandon \ OpenCV / Luxonis

    opened by Luxonis-Brandon 8
  • Training MSNet3D error

    Training MSNet3D error

    I am trying to train MSNet3D on stereodriving and KITTI2015 but faced this error:

    File "train.py", line 205, in train() File "train.py", line 98, in train loss, scalar_outputs, image_outputs = train_sample(sample, compute_metrics=do_summary) File "train.py", line 155, in train_sample disp_ests = model(imgL, imgR) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 161, in forward outputs = self.parallel_apply(replicas, inputs, kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 171, in parallel_apply return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)]) File "/opt/conda/lib/python3.8/site-packages/torch/nn/parallel/parallel_apply.py", line 86, in parallel_apply output.reraise() File "/opt/conda/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise raise self.exc_type(msg) RuntimeError: Caught RuntimeError in replica 0 on device 0. Original Traceback (most recent call last): File "/opt/conda/lib/python3.8/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker output = module(*input, **kwargs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/trainer/mobile_stereo/models/MSNet3D.py", line 124, in forward out1 = self.encoder_decoder1(cost0) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/trainer/mobile_stereo/models/MSNet3D.py", line 46, in forward conv5 = F.relu(self.conv5(conv4) + self.redir2(conv2), inplace=True) RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 2

    Does anybody know how to solve this problem? Looking forward to your reply!

    opened by YznMur 4
  • thop missing from mobilestereonet.yml

    thop missing from mobilestereonet.yml

    conda env create --file mobilestereonet.yml
    

    ... env created succesfully ...

    (base) tornado@tornado:~/mobilestereonet$ conda activate mobilestereonet
    (mobilestereonet) tornado@tornado:~/mobilestereonet$ ls
    cost.py  datasets  filenames  images  LICENSE  mobilestereonet.yml  models  prediction.py  README.md  train.py  utils
    (mobilestereonet) tornado@tornado:~/mobilestereonet$ python cost.py
    Traceback (most recent call last):
      File "cost.py", line 28, in <module>
        from thop import profile
    ModuleNotFoundError: No module named 'thop'
    

    fixed by

    pip install thop
    
    opened by DuaneNielsen 2
  • CUDA out of memory error

    CUDA out of memory error

    HI. I get out of memory error when executing train.py code. I reduced batch size but get same error. my GPU is Nvidia 1060 6GB. the error is: RuntimeError: CUDA out of memory. Tried to allocate 32.00 MiB (GPU 0; 5.94 GiB total capacity; 4.78 GiB already allocated; 27.19 MiB free; 4.80 GiB reserved in total by PyTorch)

    I appreciate any help to fix this error. thanks in advance.

    update: I could successfully train a model with batch size 1 but with batch size greater than 1 I get "out of memory error" which is discussed above.

    opened by AminA193 2
  • where to download the right scene flow dataset for pretraining?

    where to download the right scene flow dataset for pretraining?

    could you point me to where to download the right dataset for SF pretraining?

    After follow Sceneflow hyperlink, I downloaded Sceneflow disparity and frames_finalpass dataset.

    But when I checked ./filenames/sceneflow_train.txt, the file path are different from dataset:

    ./filenames/sceneflow_train.txt: for example: frames_finalpass/TRAIN/15mm_focallength/scene_backwards/slow/left/0224.png frames_finalpass/TRAIN/A/0605/left/0015.png frames_finalpass/TRAIN/B/0665/left/0006.png

    in the downloaded dataset: for example: frames_finalpass/15mm_focallength/scene_backwards/slow/left/0224.png there is no TRAIN/, TRAIN/A/ or TRAIN/B directories.

    Where is TRAIN/, TRAIN/A/, or TRAIN/B from? Is there a script that I can run to automatically download all the dataset needed and prepare them in the right directory hierarchy as specified in ./filenames/*.txt? Please advise.

    Thank you very much for your help in advance.

    opened by ynjiun 1
  • File names in file list don't seem to match file names in dataset(s)

    File names in file list don't seem to match file names in dataset(s)

    e.g. https://github.com/cogsys-tuebingen/mobilestereonet/blob/main/filenames/ds_test.txt#L1 doesn't seem to match the filenames in DrivingStereo as in the dataset provided on the linked website: https://drivingstereo-dataset.github.io/, which, e.g., are in the form 2018-07-11-14-48-52_2018-07-11-15-45-53-241.jpg. also the folder structure seems to be different. it seems to be the same issue for SceneFlow. is there any mismatch in the version of the dataset(s) or preprocessing required? in case, is the preprocessing described somewhere (maybe i missed it?).

    opened by schmidtp1 1
  • How I can reduce GPU memory usage

    How I can reduce GPU memory usage

    my device is 3080 16GB, but with the original code, I can only train with batch_size=1, otherwise, cuda out of memory.

    I tried with Mixed Precision, and I can increase batch_size to 2, how can I train with large batch size without dropping accuracy.

    opened by Qjizhi 1
  • Legacy autograd function with non-static forward method is deprecated

    Legacy autograd function with non-static forward method is deprecated

    Hi, i am using Cuda11.1 and encountered following error. RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

    def make_nograd_func(func): def wrapper(*f_args, **f_kwargs): with torch.no_grad(): ret = func(*f_args, **f_kwargs) return ret return wrapper

    This is the function that throws the error while calling func()

    opened by blackHorz 1
  • train the network

    train the network

    Thank you for your great work. I want to see the details of the the extension from 2D to 3D convolution and find there is no model ! I noticed a record of detete, is there something wrong? waiting for the rest, thank you again.

    opened by fengkai11 1
  • could you please share your model files?

    could you please share your model files?

    i want to verify other methods with yours,could you please share your model files?My mail address is [email protected]. Thanks a lot. @draeger

    opened by XiongWei1012 0
  • Have tried monochrome stereo pair input?

    Have tried monochrome stereo pair input?

    Hi,

    I am impressed by your work and tried to run prediction on kitti dataset. It looks good.

    But when I tried to run prediction on a monochrome dataset captured by an oak-d stereo camera, the results looks like random noise. Just wondering if you ever tried to run your model using monochrome input or not and how was the performance?

    If you like I attached a pair of monochrome stereo images below for your trial. Please let me know how's your test result looks like. Thanks a lot 4382_left 4382_right

    .

    opened by ynjiun 0
  • How to set the maxdisp value for a custom dataset?

    How to set the maxdisp value for a custom dataset?

    Does the maxdisp value has a influence on the result of inference time or the performance? Besides, the result does not work well on my own dataset, I guess it is the problem of maxdisp value.

    opened by hillaric 1
Owner
Cognitive Systems Research Group
Autonomous Mobile Robots; Bioinformatics; Chemo- and Geoinformatics; Evolutionary Algorithms; Machine Learning
Cognitive Systems Research Group
the code for our CVPR 2021 paper Bilateral Grid Learning for Stereo Matching Network [BGNet]

BGNet This repository contains the code for our CVPR 2021 paper Bilateral Grid Learning for Stereo Matching Network [BGNet] Environment Python 3.6.* C

3DCV developer 87 Nov 29, 2022
Stacked Recurrent Hourglass Network for Stereo Matching

SRH-Net: Stacked Recurrent Hourglass Introduction This repository is supplementary material of our RA-L submission, which helps reviewers to understan

null 28 Jan 3, 2023
Pytorch reimplementation of PSM-Net: "Pyramid Stereo Matching Network"

This is a Pytorch Lightning version PSMNet which is based on JiaRenChang/PSMNet. use python main.py to start training. PSM-Net Pytorch reimplementatio

XIAOTIAN LIU 1 Nov 25, 2021
Python scripts form performing stereo depth estimation using the high res stereo model in PyTorch .

PyTorch-High-Res-Stereo-Depth-Estimation Python scripts form performing stereo depth estimation using the high res stereo model in PyTorch. Stereo dep

Ibai Gorordo 26 Nov 24, 2022
CFNet: Cascade and Fused Cost Volume for Robust Stereo Matching(CVPR2021)

CFNet(CVPR 2021) This is the implementation of the paper CFNet: Cascade and Fused Cost Volume for Robust Stereo Matching, CVPR 2021, Zhelun Shen, Yuch

null 106 Dec 28, 2022
Local Similarity Pattern and Cost Self-Reassembling for Deep Stereo Matching Networks

Local Similarity Pattern and Cost Self-Reassembling for Deep Stereo Matching Networks Contributions A novel pairwise feature LSP to extract structural

null 31 Dec 6, 2022
The official implementation code of "PlantStereo: A Stereo Matching Benchmark for Plant Surface Dense Reconstruction."

PlantStereo This is the official implementation code for the paper "PlantStereo: A Stereo Matching Benchmark for Plant Surface Dense Reconstruction".

Wang Qingyu 14 Nov 28, 2022
✨✨✨An awesome open source toolbox for stereo matching.

OpenStereo This is an awesome open source toolbox for stereo matching. Supported Methods: BM SGM(T-PAMI'07) GCNet(ICCV'17) PSMNet(CVPR'18) StereoNet(E

Wang Qingyu 6 Nov 4, 2022
Code for C2-Matching (CVPR2021). Paper: Robust Reference-based Super-Resolution via C2-Matching.

C2-Matching (CVPR2021) This repository contains the implementation of the following paper: Robust Reference-based Super-Resolution via C2-Matching Yum

Yuming Jiang 151 Dec 26, 2022
A lightweight Python-based 3D network multi-agent simulator. Uses a cell-based congestion model. Calculates risk, loudness and battery capacities of the agents. Suitable for 3D network optimization tasks.

AMAZ3DSim AMAZ3DSim is a lightweight python-based 3D network multi-agent simulator. It uses a cell-based congestion model. It calculates risk, battery

Daniel Hirsch 13 Nov 4, 2022
A Python implementation of the Locality Preserving Matching (LPM) method for pruning outliers in image matching.

LPM_Python A Python implementation of the Locality Preserving Matching (LPM) method for pruning outliers in image matching. The code is established ac

AoxiangFan 11 Nov 7, 2022
Lightweight mmm - Lightweight (Bayesian) Media Mix Model

Lightweight (Bayesian) Media Mix Model This is not an official Google product. L

Google 342 Jan 3, 2023
Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities

ORB-SLAM2 Authors: Raul Mur-Artal, Juan D. Tardos, J. M. M. Montiel and Dorian Galvez-Lopez (DBoW2) 13 Jan 2017: OpenCV 3 and Eigen 3.3 are now suppor

Raul Mur-Artal 7.8k Dec 30, 2022
Python and C++ implementation of "MarkerPose: Robust real-time planar target tracking for accurate stereo pose estimation". Accepted at LXCV @ CVPR 2021.

MarkerPose: Robust real-time planar target tracking for accurate stereo pose estimation This is a PyTorch and LibTorch implementation of MarkerPose: a

Jhacson Meza 47 Nov 18, 2022
Pytorch codes for "Self-supervised Multi-view Stereo via Effective Co-Segmentation and Data-Augmentation"

Self-Supervised-MVS This repository is the official PyTorch implementation of our AAAI 2021 paper: "Self-supervised Multi-view Stereo via Effective Co

hongbin_xu 127 Jan 4, 2023
COLMAP - Structure-from-Motion and Multi-View Stereo

COLMAP About COLMAP is a general-purpose Structure-from-Motion (SfM) and Multi-View Stereo (MVS) pipeline with a graphical and command-line interface.

null 4.7k Jan 7, 2023
Hierarchical Memory Matching Network for Video Object Segmentation (ICCV 2021)

Hierarchical Memory Matching Network for Video Object Segmentation Hongje Seong, Seoung Wug Oh, Joon-Young Lee, Seongwon Lee, Suhyeon Lee, Euntai Kim

Hongje Seong 72 Dec 14, 2022
Hierarchical Memory Matching Network for Video Object Segmentation (ICCV 2021)

Hierarchical Memory Matching Network for Video Object Segmentation Hongje Seong, Seoung Wug Oh, Joon-Young Lee, Seongwon Lee, Suhyeon Lee, Euntai Kim

Hongje Seong 26 Sep 26, 2021
BMN: Boundary-Matching Network

BMN: Boundary-Matching Network A pytorch-version implementation codes of paper: "BMN: Boundary-Matching Network for Temporal Action Proposal Generatio

qinxin 260 Dec 6, 2022