IDEA-Research / GroundingDINO

[ECCV 2024] Official implementation of the paper "Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection"
https://arxiv.org/abs/2303.05499
Apache License 2.0
6.2k stars 651 forks source link

NameError: name '_C' is not defined #230

Open mhajjaj opened 11 months ago

mhajjaj commented 11 months ago

Hi, How to fix this error: NameError: name '_C' is not defined

this is my info. CUDA is available. CUDA Version: 11.8 Number of GPU devices: 1 GPU 0: NVIDIA GeForce RTX 4090

+-----------------------------------------------------------------------------+ | NVIDIA-SMI 528.24 Driver Version: 528.24 CUDA Version: 12.0 | |-------------------------------+----------------------+----------------------+ | GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... WDDM | 00000000:01:00.0 On | Off | | 31% 30C P8 14W / 450W | 916MiB / 24564MiB | 2% Default | | | | N/A | +-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 1984 C+G C:\Windows\System32\dwm.exe N/A | | 0 N/A N/A 6096 C+G ...lPanel\SystemSettings.exe N/A | | 0 N/A N/A 6240 C+G C:\Windows\explorer.exe N/A | | 0 N/A N/A 6400 C+G ...045.47\msedgewebview2.exe N/A | | 0 N/A N/A 7336 C+G ...artMenuExperienceHost.exe N/A | | 0 N/A N/A 7376 C+G ...n1h2txyewy\SearchHost.exe N/A | | 0 N/A N/A 8960 C+G ...oft\OneDrive\OneDrive.exe N/A | ... | 0 N/A N/A 12496 C+G ...1.0.5.0\GoogleDriveFS.exe N/A | | 0 N/A N/A 13880 C+G ...ck\app-4.34.121\slack.exe N/A | | 0 N/A N/A 15160 C+G ...ge\Application\msedge.exe N/A | +-----------------------------------------------------------------------------+ nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022 Cuda compilation tools, release 11.8, V11.8.89 Build cuda_11.8.r11.8/compiler.31833905_0 torch: 2.0 ; cuda: cu118 roboflow: 1.1.6 ; supervision: 0.4.0

qq846511277 commented 11 months ago

I have also encountered the same error as you. Have you resolved it?

qq846511277 commented 11 months ago

torch: 2.0 ;cuda:cu118

isolanomr commented 11 months ago

I'm facing the same error when doing inferences from Jupyter Notebook. Has anyone been able to solve this?

isolanomr commented 11 months ago

I'm facing the same error when doing inferences from Jupyter Notebook. Has anyone been able to solve this?

Hello there!

First of all, what I found as the source of the problem is that, in order to be able to execute this in the GPU, it is needed to have ever

I downloaded a torch version compatible with CUDA 11.8, and in my case, the problem was that the version of my Nvidia CUDA toolkit did not match the torch version compilation. I installed the toolkit directly from the source: https://developer.nvidia.com/cuda-11-8-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local for CUDA version 11.8 and Ubuntu 20.04.

With all that, it was enough to follow the installation procedures they mention in the README: https://github.com/IDEA-Research/GroundingDINO#hammer_and_wrench-install. In my case, the path where the CUDA toolkit was installed was: /usr/local/cuda which was pointing to /usr/local/cuda-11.8/.

That was enough in my case. After the pip install -e ., finally the _C package required to use the GPU was installed and it worked.

qq846511277 commented 11 months ago

从 Jupyter Notebook 进行推理时,我遇到了同样的错误。有人能够解决这个问题吗?

你好呀!

首先,我发现问题的根源在于,为了能够在 GPU 中执行此操作,需要有

我下载了与 CUDA 11.8 兼容的 torch 版本,就我而言,问题是我的 Nvidia CUDA 工具包的版本与 torch 版本编译不匹配。我直接从源安装了该工具包:https://developer.nvidia.com/cuda-11-8-0-download-archive ?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local(适用于 CUDA 版本 11.8 和 Ubuntu 20.04) 。

尽管如此,遵循他们在自述文件中提到的安装过程就足够了: https: //github.com/IDEA-Research/GroundingDINO#hammer_and_wrench-install。就我而言,CUDA 工具包的安装路径是:/usr/local/cuda指向/usr/local/cuda-11.8/.

对我来说这已经足够了。之后pip install -e .,终于安装了使用GPU所需的C包并且可以工作了。 Yes, what you said is correct. When you sent this reply, I had already succeeded. I summarized the following points, which I think are very important. Firstly, the CUDA in nvidia smi is 12.0, and the version of nvcc - V we installed must be less than or equal to 12.0. Secondly, the CUDA during pytorch installation must be consistent with the nvcc - V version, and pay attention to GroundingDINO/groundingdino/ C. Cpython-39-x86_ 64 Linux gnu so file, pip install - e each time This file will be generated, and it is also bound to the entire environment. Therefore, the author also said that every time an error occurs, the git clone repository will be directly restarted

bowen-upenn commented 6 months ago

https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/450#issuecomment-1949315114

I have encountered this issue while using Docker, but not otherwise. However, I have managed to fix it on my end.

When the script is trying to run Grounded-Segment-Anything/GroundingDINO/setup.py to compile the custom C++ operations, there was an error:

[Errno 2] No such file or directory: '/usr/local/cuda/bin/nvcc'

so I checked ls /usr/local/ in my Docker container and found there was no cuda directory at all

bin etc games include lib man sbin share src

even though running the same command outside the container showed additional directories, including

bin cuda cuda-12 cuda-12.2 cuda-9.0 dcgm etc games include lib man sbin share src

Solution: add the line -v /usr/local/cuda-12.2:/usr/local/cuda:ro \ to the run command in Makefile, as shown below

docker run --gpus all -it --rm --net=host --privileged \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -v "${PWD}":/home/appuser/working_dir \
        -v /usr/local/cuda-12.2:/usr/local/cuda:ro \
  -e DISPLAY=$DISPLAY \
  --name=gsa \
  --ipc=host -it gsa:v0

and don't forget to set yourENV CUDA_HOME /usr/local/cuda/ correctly in Dockerfile.

anas-zafar commented 3 months ago

Hi @bowen-upenn, could you please share instructions how to run this model using docker? Thanks