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.23k stars 1.31k forks source link

grounding_dino_model.predict_with_classes 'NameError: name '_C' is not defined' #450

Open Greg7000 opened 5 months ago

Greg7000 commented 5 months ago

I am currently trying the following note book from colab (https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/automated-dataset-annotation-and-evaluation-with-grounding-dino-and-sam.ipynb#scrollTo=LoD2bIptG-qO) but in local (linux container).

I can do all the steps until : # detect objects detections = grounding_dino_model.predict_with_classes( image=image, classes=enhance_class_name(class_names=CLASSES), box_threshold=BOX_TRESHOLD, text_threshold=TEXT_TRESHOLD )

However I get 'NameError: name '_C' is not defined', I do have cython in my environement.

Please note that my 'torch.cuda.is_available()' does return true.

Did anyone face that issue with grounding_dino_model.predict_with_classe?

rentainhe commented 5 months ago

hello, maybe you should try to set CUDA Runtime before compiling the environment, could you check the env param CUDA_HOME and if it is None, you should set it to the CUDA Runtime

JohanHuynh0130 commented 5 months ago

thanks for the quick response. I really appreciate ;) I fixed this by having to cd to Grounding Dino and build it again and afterwards it works :)

Greg7000 commented 5 months ago

hello, maybe you should try to set CUDA Runtime before compiling the environment, could you check the env param CUDA_HOME and if it is None, you should set it to the CUDA Runtime

Already done (maybe should double check again...). If I manage to find the time I will retest the build and keep you posted. I think I builded with CUDA_HOME but maybe I did not have cython when I first build.

bowen-upenn commented 5 months ago

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.