zhyever / Monocular-Depth-Estimation-Toolbox

Monocular Depth Estimation Toolbox based on MMSegmentation.
Apache License 2.0
903 stars 104 forks source link

Support for mmcv 1.7, CUDA 11.8 and PyTorch 1.13? #71

Closed mexicantexan closed 1 year ago

mexicantexan commented 1 year ago

Wondering if this could get support for mmcv 1.7, mmsegmentation 0.29, CUDA 11.8 and PyTorch 1.13? Currently, when attempting to use these dependencies several errors are thrown on import.

zhyever commented 1 year ago

Could you please share the errors so that I could try to help you?

mexicantexan commented 1 year ago

@zhyever just wanted to say great repo :) I ended up getting the repo to work with mmcv 1.7, CUDA 11.7, Pytorch 1.13, and mmsegmentation 0.29. My environment was Linux 22.04 with Python 3.9. Here is the script I used to set everything up.

#!/bin/bash

INSTALL_DIR="./Monocular-Depth-Estimation-Toolbox"
if [ -d "$INSTALL_DIR" ]; then
  cd Monocular-Depth-Estimation-Toolbox
  VENV_DIR="./venv"

  if [ ! -d "$INSTALL_DIR" ]; then
    # pip install pre-build reqs
    python3.9 venv venv
  fi

  . ./venv/bin/activate

  pip install wheel setuptools

  # install latest pytorch (at time of writing -> CUDA 11.7, torch 1.13)
  pip install torch torchvision torchaudio

  # install matching mmcv-full
  pip install openmim
  mim install mmcv-full

  # install matching mmsegmentation
  pip install mmsegmentation

  # install runtime reqs
  pip install -r ./requirements/runtime.txt
  # install test reqs
  pip install -r ./requirements/tests.txt
  # install docs reqs
  pip install -r ./requirements/docs.txt

  # install optional reqs
  pip install -r ./requirements/optional.txt

  # install training requirements
  pip install future tensorboard

  # install other reqs as needed
  pip install timm

  pip install -e .

  # create data directory
  if [ ! -d "./data" ]; then
    # pip install pre-build reqs
    mkdir data
  fi
  cd data

  # create nyu directory
  if [ ! -d "./nyu" ]; then
    mkdir nyu
  fi
  # create kitti directory
  if [ ! -d "./kitti" ]; then
    mkdir kitti
  fi
  # create cityscapes directory
  if [ ! -d "./cityscapes" ]; then
    mkdir cityscapes
  fi
  if [ ! -d "./cityscapesExtra" ]; then
    mkdir cityscapesExtra
  fi
  # create sunrgbd directory
  if [ ! -d "./SUNRGBD" ]; then
    mkdir SUNRGBD
  fi
  # create custom dataset
  if [ ! -d "./custom_dataset" ]; then
    mkdir custom_dataset
  fi
  cd custom_dataset
  if [ ! -d "./train" ]; then
    mkdir train
  fi
  if [ ! -d "./val" ]; then
    mkdir val
  fi
  cd ..

  # copy splits into directories
  cd ../splits
  ls . | grep "cityscapes" | xargs -I '{}' cp '{}' ../data/cityscapes
  ls . | grep "cityscapes" | xargs -I '{}' cp '{}' ../data/cityscapesExtra
  ls . | grep "kitti" | xargs -I '{}' cp '{}' ../data/kitti
  ls . | grep "nyu" | xargs -I '{}' cp '{}' ../data/nyu
  ls . | grep "SUNRGBD" | xargs -I '{}' cp '{}' ../data/SUNRGBD
  cd ..

  # optional for final test
  cp ../test.png ./data/custom_dataset/val
  cp ../test_split.txt ./data/custom_dataset
  mv ./data/custom_dataset/test_split.txt ./data/custom_dataset/nyu_test.txt

  # create checkpoint dir
  if [ ! -d "./checkpoints" ]; then
    mkdir checkpoints
  fi
  cd checkpoints

  if [ ! -f "binsformer_swinl_22k_w7_nyu.pth" ]; then
    echo "Downloading binsformer pretrained model..."
    wget -O binsformer_swinl_22k_w7_nyu.pth "https://drive.google.com/u/0/uc?id=1j1FmtXKSOD5e6HWBBd_3cwI2M11Jd_nB&export=download&confirm=t&uuid=087cc973-fe39-4ba9-9898-8186149f7cf8&at=AHV7M3di_wo97d4H-uuZZyGpWzHT:1669749786439" >/dev/null 2>&1
    echo "Done Downloading pretrained model..."
  fi

  cd ..

  if [ ! -f "./data/custom_dataset/val/test.png" ]; then
      python tools/test.py configs/binsformer/binsformer_swinl_22k_w7_nyu.py checkpoints/binsformer_swinl_22k_w7_nyu.pth --show-dir "./results"
  fi
else
  git clone https://github.com/zhyever/Monocular-Depth-Estimation-Toolbox.git

  # need to edit the following files to run the script in one go, may have to run "pip install -e ." afterwards
  echo ""
  echo "###########"
  echo "Need to edit the following:"
  echo "    - setup.py file comment out all requires"
  echo "    - setup.py add in 'Python 3.9' after 'Python3.8'"
  echo "    - depth/__init__.py change -> MMCV_MAX = '1.5.0' to MMCV_MAX = '1.7.0'"
  echo "    - configs/binsformer/binsformer_swinl_22k_w7_nyu.py change ln 79 -> data_root = 'data/nru/' to data_root = 'data/custom_dataset/'"
  echo "Once that is done rerun '. ./install'"
fi

Hopefully, this helps others.

mexicantexan commented 1 year ago

The errors I was getting were stemming from having conflicting libs i.e. mmcv-full being installed with mmcv in that instance only one is supposed to be installed