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.88k stars 696 forks source link

error: name '_C' is not defined in ms_deform_attn.py #303

Closed bhandaripratibha06 closed 8 months ago

bhandaripratibha06 commented 8 months ago

/data# /usr/bin/python3 /data/pratibha/GroundingDINO/Dino.py /data/pratibha/GroundingDINO/groundingdino_swint_ogc.pth ; exist: True /data/pratibha/GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py ; exist: True /data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/ms_deform_attn.py:31: 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!") /usr/local/lib/python3.8/dist-packages/torch/functional.py:507: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3549.) return _VF.meshgrid(tensors, kwargs) # type: ignore[attr-defined] final text_encoder_type: bert-base-uncased /usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py:962: FutureWarning: The device argument is deprecated and will be removed in v5 of Transformers. warnings.warn( /usr/local/lib/python3.8/dist-packages/torch/utils/checkpoint.py:460: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants. warnings.warn( /usr/local/lib/python3.8/dist-packages/torch/utils/checkpoint.py:90: UserWarning: None of the inputs have requires_grad=True. Gradients will be None warnings.warn( Traceback (most recent call last): File "/data/pratibha/GroundingDINO/Dino.py", line 26, in boxes, logits, phrases = predict(model=model, image=image, caption=TEXT_PROMPT, box_threshold=BOX_TRESHOLD, text_threshold=TEXT_TRESHOLD) File "/data/pratibha/GroundingDINO/groundingdino/util/inference.py", line 68, in predict outputs = model(image[None], captions=[caption]) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(args, kwargs) File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 327, in forward hs, reference, hs_enc, ref_enc, init_box_proposal = self.transformer( File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 258, in forward memory, memory_text = self.encoder( File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, kwargs) File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 576, in forward output = checkpoint.checkpoint( File "/usr/local/lib/python3.8/dist-packages/torch/_compile.py", line 24, in inner return torch._dynamo.disable(fn, recursive)(*args, *kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/_dynamo/eval_frame.py", line 489, in _fn return fn(args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/_dynamo/external_utils.py", line 17, in inner return fn(*args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/utils/checkpoint.py", line 482, in checkpoint return CheckpointFunction.apply(function, preserve, args) File "/usr/local/lib/python3.8/dist-packages/torch/autograd/function.py", line 553, in apply return super().apply(args, kwargs) # type: ignore[misc] File "/usr/local/lib/python3.8/dist-packages/torch/utils/checkpoint.py", line 261, in forward outputs = run_function(args) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 785, in forward src2 = self.self_attn( File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/ms_deform_attn.py", line 338, in forward output = MultiScaleDeformableAttnFunction.apply( File "/usr/local/lib/python3.8/dist-packages/torch/autograd/function.py", line 553, in apply return super().apply(args, **kwargs) # type: ignore[misc] File "/data/pratibha/GroundingDINO/groundingdino/models/GroundingDINO/ms_deform_attn.py", line 53, in forward output = _C.ms_deform_attn_forward( NameError: name '_C' is not defined

This error is being flashed everytime i try to find the output for the task.

Abhishek-Iyer1 commented 8 months ago

Hey, did you figure out what was causing the error? I am getting the same error but $CUDA_HOME is set correctly in the environment.

GPY11 commented 8 months ago

我也有同样的问题

advait-patel-17 commented 7 months ago

I'm also getting this error and not sure why. @GPY11 @Abhishek-Iyer1 did you figure it out? @bhandaripratibha06 mind sharing how you resolved it?

bhandaripratibha06 commented 7 months ago

If you have a CUDA environment, please make sure the environment variable CUDA_HOME is set. It will be compiled under CPU-only mode if no CUDA available. Please make sure following the installation steps strictly, otherwise the program may produce:

NameError: name '_C' is not defined If this happened, please reinstalled the groundingDINO by reclone the git and do all the installation steps again.

how to check cuda: echo $CUDA_HOME If it print nothing, then it means you haven't set up the path/

Run this so the environment variable will be set under current shell.

export CUDA_HOME=/path/to/cuda-11.3 Notice the version of cuda should be aligned with your CUDA runtime, for there might exists multiple cuda at the same time.

If you want to set the CUDA_HOME permanently, store it using:

echo 'export CUDA_HOME=/path/to/cuda' >> ~/.bashrc after that, source the bashrc file and check CUDA_HOME:

source ~/.bashrc echo $CUDA_HOME In this example, /path/to/cuda-11.3 should be replaced with the path where your CUDA toolkit is installed. You can find this by typing which nvcc in your terminal:

For instance, if the output is /usr/local/cuda/bin/nvcc, then:

export CUDA_HOME=/usr/local/cuda

yscfromchina commented 1 month ago

Windows solution, I found that this module uses the same attention module as deformable detr, so if you've used deformable detr you can change the

from groundingdino import _C

to

import MultiScaleDeformableAttention as _C

humphreyde commented 4 weeks ago

Hey, did you figure out what was causing the error? I am getting the same error but $CUDA_HOME is set correctly in the environment.

me too, $CUDA_HOME is right, and there is _C.cpython-310xxxx file in groundingdino. Did you solve it?