IDEA-Research / Grounded-Segment-Anything

Grounded SAM: Marrying Grounding DINO with Segment Anything & Stable Diffusion & Recognize Anything - Automatically Detect , Segment and Generate Anything
https://arxiv.org/abs/2401.14159
Apache License 2.0
14.22k stars 1.31k forks source link

Error: name '_C' is not defined , UserWarning: Failed to load custom C++ ops. Running on CPU mode Only! #436

Open Morizhaoyang opened 6 months ago

Morizhaoyang commented 6 months ago

torch version: 2.0.1 cuda version: 11.6

Successfully installed groundingdino-0.1.0

when i run grounding_dino_demo

python grounding_dino_demo.py

NameError: name '_C' is not defined UserWarning: Failed to load custom C++ ops. Running on CPU mode Only! warnings.warn("Failed to load custom C++ ops. Running on CPU mode Only!")

rentainhe commented 6 months ago

I was wondering if you set CUDA_HOME before installing Grounding-DINO?

Lee-ray-a commented 6 months ago

I was wondering if you set CUDA_HOME before installing Grounding-DINO?

yes, I set CUDA_HOME, still got the same error

villekuosmanen commented 5 months ago

I also had this problem, for me it was caused by groundingdino not being correctly installed. I solved it by finding a corrupted package in the environment, deleting and reinstalling it, then deleting and reinstalling groundingdino. Other reasons I could think of why it would fail would be if your system c++ compiler is not compatible with the cuda version. You should check the output of installing the package and see if it helps. There are also many other issues recorded for this in the package, you may find those helpful.

There are many other reasons why an installation would not be successful so your mileage may vary.

roland-diffusedrive commented 5 months ago

I also had this problem, for me it was caused by groundingdino not being correctly installed. I solved it by finding a corrupted package in the environment, deleting and reinstalling it, then deleting and reinstalling groundingdino. Other reasons I could think of why it would fail would be if your system c++ compiler is not compatible with the cuda version. You should check the output of installing the package and see if it helps. There are also many other issues recorded for this in the package, you may find those helpful.

There are many other reasons why an installation would not be successful so your mileage may vary.

@villekuosmanen Do you happen to remember which package was corrupted? The reason why I'm asking is that all the installation steps are successful for me, but still, I get the _C error when trying to run grounding dino.

SynUW commented 5 months ago

for those who still have this error. maybe you can first run the python setup.py install after cd to GroundingDINO. Then if an error is encountered, e.g., fatal error C1083, you should install the Win10/11 SDK using the Visual Studio installer

haviduck commented 5 months ago

i did:

set BUILD_WITH_CUDA=True
set CUDA_HOME="path"
set AM_I_DOCKER=False

cd groundingdino

python setup.py build

python setup.py install
bowen-upenn commented 5 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.

kshitijagrwl commented 3 months ago

i did:

set BUILD_WITH_CUDA=True
set CUDA_HOME="path"
set AM_I_DOCKER=False

cd groundingdino

python setup.py build

python setup.py install

This solved for me. Thanks!

wow0112 commented 2 months ago

for those who still have this error. maybe you can first run the python setup.py install after cd to GroundingDINO. Then if an error is encountered, e.g., fatal error C1083, you should install the Win10/11 SDK using the Visual Studio installer

you are the best!! thank u so much!! love u !!