Grounded-Segment-Anything icon indicating copy to clipboard operation
Grounded-Segment-Anything copied to clipboard

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

Open Morizhaoyang opened this issue 1 year ago • 9 comments

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!")

Morizhaoyang avatar Jan 18 '24 02:01 Morizhaoyang

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

rentainhe avatar Jan 18 '24 09:01 rentainhe

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

yes, I set CUDA_HOME, still got the same error

Lee-ray-a avatar Jan 19 '24 02:01 Lee-ray-a

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 avatar Jan 21 '24 20:01 villekuosmanen

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.

roland-diffusedrive avatar Feb 08 '24 12:02 roland-diffusedrive

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

SynUW avatar Feb 12 '24 03:02 SynUW

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

haviduck avatar Feb 15 '24 14:02 haviduck

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 your ENV CUDA_HOME /usr/local/cuda/ correctly in Dockerfile.

bowen-upenn avatar Feb 16 '24 20:02 bowen-upenn

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!

kshitijagrwl avatar Apr 11 '24 09:04 kshitijagrwl

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 !!

wow0112 avatar May 07 '24 14:05 wow0112