aim-uofa / AdelaiDepth

This repo contains the projects: 'Virtual Normal', 'DiverseDepth', and '3D Scene Shape'. They aim to solve the monocular depth estimation, 3D scene reconstruction from single image problems.
Creative Commons Zero v1.0 Universal
1.07k stars 145 forks source link

No module named 'lib' error in AdelaiDepth_ResNet101.ipynb #65

Closed EllieFar closed 1 year ago

EllieFar commented 1 year ago

Hi. Thanks for your nice work. I tried to run AdelaiDepth_ResNet101.ipynb (here) but I got error like:

Traceback (most recent call last): File "/content/AdelaiDepth/LeReS/Minist_Test/tools/test_depth.py", line 9, in from lib.multi_depth_model_woauxi import RelDepthModel ModuleNotFoundError: No module named 'lib'

I tried below solution mentioned in https://github.com/aim-uofa/AdelaiDepth/issues/11#issuecomment-953388438. but still didn't work.

import sys, os
sys.path.insert(1, os.getcwd()) 

I also tried below solution mentioned in https://github.com/aim-uofa/AdelaiDepth/issues/7, but did not work

import os
import sys
sys.path.insert(1, os.path.abspath(".")) # insert the current directory 
from lib.multi_depth_model_woauxi import RelDepthModel
from lib.net_tools import load_ckpt

Do you have any idea how can I solve it? I would appreciate it.

guangkaixu commented 1 year ago

Hi, this bug happens due to the incorrect "PYTHONPATH". I don't have the right to modify the google colab ipynb file. You can modify it as follows:

Download libraries and clone git project(run only for first time)

#@title Download libraries and clone git project(run only for first time)
%cd /content/
!git clone https://github.com/aim-uofa/AdelaiDepth
!wget -O /content/AdelaiDepth/LeReS/Minist_Test/res101.pth https://cloudstor.aarnet.edu.au/plus/s/lTIJF4vrvHCAI31/download
import sys
import os
sys.path.append('/content/AdelaiDepth/Minist_Test/LeReS/')
os.environ["PYTHONPATH"] += (":/content/AdelaiDepth/Minist_Test/LeReS")
!echo "$PYTHONPATH"
!pip3 install ipykernel matplotlib opencv-python
!pip3 install torch==1.6.0 torchvision==0.7.0
#cudatoolkit==10.2
from IPython.display import clear_output
clear_output()

Clean output directory

#@title Clean output directory
%%shell
if [ -e /content/AdelaiDepth/LeReS/Minist_Test/test_images ]; then
  if [ -n "`ls -A /content/AdelaiDepth/LeReS/Minist_Test/test_images/`" ]; then
    rm -rf /content/AdelaiDepth/LeReS/Minist_Test/test_images/*
    echo "Cleaned"
  fi
elif [ ! -e /content/AdelaiDepth/LeReS/Minist_Test/test_images ]; then
  mkdir /content/AdelaiDepth/LeReS/Minist_Test/test_images
  mkdir /content/AdelaiDepth/LeReS/Minist_Test/test_images/outputs
  echo "Created directories and cleaned"
fi

Upload images(png, jpg works fine, also you can upload multiple images)

#@title Upload images(png, jpg works fine, also you can upload multiple images)
%cd /content/AdelaiDepth/LeReS/Minist_Test/test_images/
from google.colab import files
image = files.upload()
#for n in image.keys():
#  print("{name} succesfully uploaded!".format(name = n))

Run network

#@title Run network
%cd /content/AdelaiDepth/LeReS/Minist_Test
%env PYTHONPATH=/content/AdelaiDepth/LeReS/Minist_Test
!echo "$PYTHONPATH"
!python3 ./tools/test_depth.py --load_ckpt res101.pth --backbone resnext101
!echo "Done!"

Download results

#@title Download results
from google.colab import files
%cd /content/AdelaiDepth/LeReS/Minist_Test/test_images/
!find outputs/ -name "*-depth_raw.png" | zip -r result.zip -@
files.download("result.zip")
EllieFar commented 1 year ago

@guangkaixu Thank you very much for your response. It resolved the issue!