recognize-anything
recognize-anything copied to clipboard
NameError: name '_C' is not defined
Traceback (most recent call last):
File "/data10/cyb/SAM/SAM1/recognize-anything/test.py", line 261, in <module>
ram_tags, ram_chinese_tags, ram_out_image = inference_with_ram(in_img, do_det_seg=True)
File "/data10/cyb/SAM/SAM1/recognize-anything/test.py", line 253, in inference_with_ram
return inference(img, None, do_det_seg, "RAM", ram_model, grounding_dino_model, sam_model)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/test.py", line 165, in inference
boxes_filt, scores, pred_phrases = get_grounding_output(
File "/data10/cyb/SAM/SAM1/recognize-anything/test.py", line 56, in get_grounding_output
outputs = model(image[None], captions=[caption])
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 313, in forward
hs, reference, hs_enc, ref_enc, init_box_proposal = self.transformer(
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 258, in forward
memory, memory_text = self.encoder(
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 577, in forward
output = checkpoint.checkpoint(
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/_compile.py", line 24, in inner
return torch._dynamo.disable(fn, recursive)(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/_dynamo/eval_frame.py", line 328, in _fn
return fn(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
return fn(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/utils/checkpoint.py", line 451, in checkpoint
return CheckpointFunction.apply(function, preserve, *args)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/autograd/function.py", line 539, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/utils/checkpoint.py", line 230, in forward
outputs = run_function(*args)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py", line 786, in forward
src2 = self.self_attn(
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/ms_deform_attn.py", line 338, in forward
output = MultiScaleDeformableAttnFunction.apply(
File "/data5/shitao/anaconda/envs/ab/lib/python3.9/site-packages/torch/autograd/function.py", line 539, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
File "/data10/cyb/SAM/SAM1/recognize-anything/Grounded-Segment-Anything/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 seems like an issue not related to RAM, but rather to GroundingDINO/Grounding SAM. There is a version of the Multi-Scale Deformable Attention Function that this library attempts to build using CUDA tools during the installation process. If this fails due to a CUDA environment variable not being set, the code inside ms_deform_attn.py will still try to look for this function. You can either restart the installation process (I would recommend following the procedure outlined for GroundingDINO in their repo), or you could try to fix it as I proposed here: https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/469#issuecomment-2123389938.