Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error importing sam2/_C.so when running the video_predictor_example.ipynb #77

Closed
rishabh297 opened this issue Jul 31, 2024 · 5 comments
Closed

Comments

@rishabh297
Copy link

rishabh297 commented Jul 31, 2024

I am getting the following error when I run the line of code that says:

labels = np.array([1], np.int32)
_, out_obj_ids, out_mask_logits = predictor.add_new_points(
    inference_state=inference_state,
    frame_idx=ann_frame_idx,
    obj_id=ann_obj_id,
    points=points,
    labels=labels,
)

The main import error message is:

ImportError: /content/segment-anything-2/sam2/_C.so: undefined symbol: _ZN3c1015SmallVectorBaseIjE8grow_podEPKvmm

This is the entire error:


ImportError Traceback (most recent call last)
in <cell line: 8>()
6 # for labels, 1 means positive click and 0 means negative click
7 labels = np.array([1], np.int32)
----> 8 _, out_obj_ids, out_mask_logits = predictor.add_new_points(
9 inference_state=inference_state,
10 frame_idx=ann_frame_idx,

4 frames
/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py in decorate_context(*args, **kwargs)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
116
117 return decorate_context

/content/segment-anything-2/sam2/sam2_video_predictor.py in add_new_points(self, inference_state, frame_idx, obj_id, points, labels, clear_old_points, normalize_coords)
219 # Clamp the scale of prev_sam_mask_logits to avoid rare numerical issues.
220 prev_sam_mask_logits = torch.clamp(prev_sam_mask_logits, -32.0, 32.0)
--> 221 current_out, _ = self._run_single_frame_inference(
222 inference_state=inference_state,
223 output_dict=obj_output_dict, # run on the slice of a single object

/content/segment-anything-2/sam2/sam2_video_predictor.py in _run_single_frame_inference(self, inference_state, output_dict, frame_idx, batch_size, is_init_cond_frame, point_inputs, mask_inputs, reverse, run_mem_encoder, prev_sam_mask_logits)
808 # potentially fill holes in the predicted masks
809 if self.fill_hole_area > 0:
--> 810 pred_masks_gpu = fill_holes_in_mask_scores(
811 pred_masks_gpu, self.fill_hole_area
812 )

/content/segment-anything-2/sam2/utils/misc.py in fill_holes_in_mask_scores(mask, max_area)
221 # (background regions are those with mask scores <= 0)
222 assert max_area > 0, "max_area must be positive"
--> 223 labels, areas = get_connected_components(mask <= 0)
224 is_hole = (labels > 0) & (areas <= max_area)
225 # We fill holes with a small positive mask score (0.1) to change them to foreground.

/content/segment-anything-2/sam2/utils/misc.py in get_connected_components(mask)
59 components for foreground pixels and 0 for background pixels.
60 """
---> 61 from sam2 import _C
62
63 return _C.get_connected_componnets(mask.to(torch.uint8).contiguous())

ImportError: /content/segment-anything-2/sam2/_C.so: undefined symbol: _ZN3c1015SmallVectorBaseIjE8grow_podEPKvmm

Can you please help out with this issue. It would enable me to proceed with the project. Not sure how to fix it.

@vanamagautam24
Copy link

vanamagautam24 commented Jul 31, 2024

!python setup.py build_ext --inplace worked for me

run the above command at the beginning of the jupyter / colab notebook.

@iAsakiT3T
Copy link

I'm having the same issue.Pls have you solved it?

@topshu
Copy link

topshu commented Aug 1, 2024

@vanamagautam24 thanks! it works for me!

@ronghanghu
Copy link
Contributor

Hi, we have added INSTALL.md as an installation FAQ.

Regarding this error:

This is usually because you haven't run the pip install -e ".[demo]" step above or the installation failed. Please install SAM 2 first, and see the other issues if your installation fails. (You may also try python setup.py build_ext --inplace in the repo root as others suggested in https://github.com/facebookresearch/segment-anything-2/issues/77)

@rishabh297
Copy link
Author

rishabh297 commented Aug 7, 2024

Thank you, What worked for me was running these commands in my Colab Notebook:

%cd /content/segment-anything-2
!python setup.py build_ext --inplace

Run the above commands after building the relevant sam2 model. This should help build the _C module appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants