JiehongLin / SAM-6D

[CVPR2024] Code for "SAM-6D: Segment Anything Model Meets Zero-Shot 6D Object Pose Estimation".
353 stars 30 forks source link

Update README.md, dependencies and scripts #41

Closed savidini closed 6 months ago

savidini commented 7 months ago

First of all, I would like to take this opportunity to thank the authors for the great work and congratulate them on the acceptance of the paper for CVPR 2024. 🥳

This PR fixes several minor issues with the goal of making the SAM-6D code more accessible:

1. Changes in README.MD

2. Updated environment.yml

3. Changes in prepare.sh and demo.sh

Disclaimer: I have tested the changes on several local machines and cloud servers. However only for running inference and not for training the PEM, as described in Pose Estimation Model (PEM) for SAM-6D.

Best regards!

monajalal commented 7 months ago

@savidini

I followed your repo and still the prepare.sh failed.

(sam6d) mona@ada:/data/savidini/SAM-6D/SAM-6D$ sh prepare.sh
running install
/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  self.initialize_options()
running bdist_egg
running egg_info
creating pointnet2.egg-info
writing pointnet2.egg-info/PKG-INFO
writing dependency_links to pointnet2.egg-info/dependency_links.txt
writing top-level names to pointnet2.egg-info/top_level.txt
writing manifest file 'pointnet2.egg-info/SOURCES.txt'
reading manifest file 'pointnet2.egg-info/SOURCES.txt'
writing manifest file 'pointnet2.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
Traceback (most recent call last):
  File "/data/savidini/SAM-6D/SAM-6D/Pose_Estimation_Model/model/pointnet2/setup.py", line 16, in <module>
    setup(
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/__init__.py", line 104, in setup
    return distutils.core.setup(**attrs)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 184, in setup
    return run_commands(dist)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
    dist.run_commands()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/dist.py", line 967, in run_command
    super().run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/install.py", line 87, in run
    self.do_egg_install()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/install.py", line 139, in do_egg_install
    self.run_command('bdist_egg')
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
    self.distribution.run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/dist.py", line 967, in run_command
    super().run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/bdist_egg.py", line 167, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/bdist_egg.py", line 153, in call_command
    self.run_command(cmdname)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
    self.distribution.run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/dist.py", line 967, in run_command
    super().run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/install_lib.py", line 11, in run
    self.build()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/command/install_lib.py", line 110, in build
    self.run_command('build_ext')
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
    self.distribution.run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/dist.py", line 967, in run_command
    super().run_command(command)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 91, in run
    _build_ext.run(self)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 359, in run
    self.build_extensions()
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 523, in build_extensions
    _check_cuda_version(compiler_name, compiler_version)
  File "/home/mona/anaconda3/envs/sam6d/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 414, in _check_cuda_version
    raise RuntimeError(CUDA_MISMATCH_MESSAGE.format(cuda_str_version, torch.version.cuda))
RuntimeError: 
The detected CUDA version (11.8) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.
(sam6d) mona@ada:/data/savidini/SAM-6D/SAM-6D$ nvidia-smi
Wed Apr 17 14:53:26 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.12             Driver Version: 535.104.12   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA RTX 6000 Ada Gene...    On  | 00000000:52:00.0  On |                  Off |
| 30%   42C    P3              51W / 300W |   1331MiB / 49140MiB |      4%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      4197      G   /usr/lib/xorg/Xorg                          501MiB |
|    0   N/A  N/A      4350      G   /usr/bin/gnome-shell                         42MiB |
|    0   N/A  N/A      4835      G   ...AAAAAAAACAAAAAAAAAA= --shared-files       56MiB |
|    0   N/A  N/A      5008      G   ...ures=SpareRendererForSitePerProcess      122MiB |
|    0   N/A  N/A      5683      G   ...irefox/4090/usr/lib/firefox/firefox      395MiB |
|    0   N/A  N/A     34019      G   ...sion,SpareRendererForSitePerProcess      129MiB |
|    0   N/A  N/A     49250      G   ...6559462,13394386653006582258,262144       46MiB |
+---------------------------------------------------------------------------------------+
(sam6d) mona@ada:/data/savidini/SAM-6D/SAM-6D$ git log
commit 9d6cd3159740da1b659a961828353ba939feebff (HEAD -> main, origin/main, origin/HEAD)
Author: David Wendorff <42057206+savidini@users.noreply.github.com>
Date:   Tue Mar 26 10:46:18 2024 +0100

    Update README.md, dependencies and scripts

    Update README.md to make SAM-6D more accessible. Many version upgrade in conda environment file. Minor changes to prepare.sh and demo.sh script to avoid possible errors.

commit fca43b6aa9effa8b6aea59a5cf8bf91014cfa558
Author: Jiehong <mortimer.jh.lin@gmail.com>
Date:   Thu Mar 7 15:16:30 2024 +0800

    Update README.md

Could you please suggest a fix?

monajalal commented 7 months ago

also regarding 2, you may find my answer here useful https://blender.stackexchange.com/a/306270/96194

(blenderproc) mona@ada:~/BlenderProc$ blenderproc quickstart --custom-blender-path ~/Downloads/blender-3.5.1-linux-x64

(blenderproc) mona@ada:~/BlenderProc$ blenderproc run ./blenderproc/scripts/quickstart.py --custom-blender-path ~/Downloads/blender-3.5.1-linux-x64
savidini commented 7 months ago

@monajalal

The detected CUDA version (11.8) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.

I am a bit confused by your error message, as neither version of CUDA should be installed or used.

Can you please check if these are pointing to your sam6d environment:

conda activate sam6d
which python
which pip
which nvcc

I suspect that there may be a misconfiguration that is causing the wrong packages to be used. If this is the case, please check echo $PATH.

Also, the following output would be helpful for further debugging.

conda activate sam6d
conda info
conda list

I have tested the updated environment.yml on several different systems without problems, but it may need some improvements.

I would appreciate your feedback.

david1309 commented 6 months ago

@monajalal

I also used to get this message when compiling PointNet:

The detected CUDA version (11.8) mismatches the version that was used to compile
PyTorch (12.1). Please make sure to use the same CUDA versions.

The reason why this occurs is that torch==2.2.1 is compiled by default for CUDA 12.1, and your nvcc is pointing towards your CUDA 11.8 installation. In theory, @savidini updated environment.yaml installs cuda=12.0 which solves this issue, but in my machine, I still continue getting the error you get (at least for this fork at 9d6cd31)

To fix this I had to manually obtain CUDA 12.1 from NVIDIA’s CUDA website and run the file script via sudo sh cuda_12.1.0_530.30.02_linux.run. Make sure to remember where you install the cuda tool kit. Once you have installed it, you need to point nvcc to this toolkit. To do so export the following env variables to point to the directory where you installed the CUDA 12.1:

export CUDA_HOME=/home/YOUR_USER/PATH_CUDA_YOU_INSTALLED/cuda-12.1/
export PATH=/home/YOUR_USER/PATH_CUDA_YOU_INSTALLED/cuda-12.1/bin:$PATH
export LD_LIBRARY_PATH=/home/YOUR_USER/PATH_CUDA_YOU_INSTALLED/cuda-12.1/lib64:$LD_LIBRARY_PATH

If you then run nvcc --version you should see it's version 12.1.

Once this is set, you should be able to compile PointNet without the pytorch version conflict you saw before

david1309 commented 6 months ago

Alternatively, if you don't want to manually install CUDA 12.1, something that also worked for me was to use the original repo from @JiehongLin which uses torch==2.0.0. This version of torch was compiled using CUDA 11.7 and thus you can install this CUDA version by directly specifying cudatoolkit-dev=11.7on the conda environmnent.yaml file. Like this:

NOTE: I also changed the blenderproc==2.7.0 so that it doesn't fail when downloading blender.

environment.yaml with cudatoolkit-dev=11.7: ``` name: sam6d channels: - xformers - conda-forge - pytorch - nvidia - defaults dependencies: - cudatoolkit-dev=11.7 - pip - python=3.9.6 - pip: - torch==2.0.0 - torchvision==0.15.1 - fvcore - xformers==0.0.18 - torchmetrics==0.10.3 - blenderproc==2.7.0 - opencv-python # ISM - omegaconf - ruamel.yaml - hydra-colorlog - hydra-core - gdown - pandas - imageio - pyrender - pytorch-lightning==1.8.1 - pycocotools - distinctipy - git+https://github.com/facebookresearch/segment-anything.git # SAM - ultralytics==8.0.135 # FastSAM # PEM - timm - gorilla-core==0.2.7.8 - trimesh==4.0.8 - gpustat==1.0.0 - imgaug - einops ```

Once the conda environment is created and activated, conda takes care of appending to the env variables the path to the cudatoolkit-dev=11.7 and you shouldn't have issues when compiling PointNet.