Git Product home page Git Product logo

sam-clip-segmentation's Introduction

sam-clip-segmentation

Zero Shot Segmentation using Meta's SAM && OpenAI's CLIP

Installation

Install SAM: I recommend following Meta's installation instructions here

But ultimately I used the pip installation listed below:

pip install git+https://github.com/facebookresearch/segment-anything.git

Install CLIP: I recommend following CLIP instructions here

But ultimately I used the pip installation listed below:

pip install git+https://github.com/openai/CLIP.git

How to Run:

The notebook in this repo steps through generating an overlay image





sam-clip-segmentation's People

Contributors

isayahc avatar jvpassarelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

isayahc eichi7

sam-clip-segmentation's Issues

AssertionError: set_torch_image input must be BCHW with long side 1024.

Hi! I have an image "image.png" in the current directory and I ran sam_masks = samclip.generate_image_sam_mask('image.png').

The assertion error in Colab is as followed:

AssertionError Traceback (most recent call last)
in <cell line: 2>()
1 classes = ["sky", "building"]
----> 2 sam_masks = samclip.generate_image_sam_mask('image.png')
3 # sam_masks = mask_generator.generate(image)
4 overlayed_img = samclip.get_overlay_img(sam_masks, classes)
5 overlay_pth = "output.jpg"

7 frames
in generate_image_sam_mask(self, img_pth, stability_score_threshold, predicted_iou_threshold)
151
152 mask_generator = SamAutomaticMaskGenerator(self.sam)
--> 153 masks = mask_generator.generate(self.cur_img_np)
154
155 og_masks = masks.copy()

/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

/usr/local/lib/python3.10/dist-packages/segment_anything/automatic_mask_generator.py in generate(self, image)
161
162 # Generate masks
--> 163 mask_data = self._generate_masks(image)
164
165 # Filter small disconnected regions and holes in masks

/usr/local/lib/python3.10/dist-packages/segment_anything/automatic_mask_generator.py in _generate_masks(self, image)
204 data = MaskData()
205 for crop_box, layer_idx in zip(crop_boxes, layer_idxs):
--> 206 crop_data = self._process_crop(image, crop_box, layer_idx, orig_size)
207 data.cat(crop_data)
208

/usr/local/lib/python3.10/dist-packages/segment_anything/automatic_mask_generator.py in _process_crop(self, image, crop_box, crop_layer_idx, orig_size)
234 cropped_im = image[y0:y1, x0:x1, :]
235 cropped_im_size = cropped_im.shape[:2]
--> 236 self.predictor.set_image(cropped_im)
237
238 # Get points for this crop

/usr/local/lib/python3.10/dist-packages/segment_anything/predictor.py in set_image(self, image, image_format)
58 input_image_torch = input_image_torch.permute(2, 0, 1).contiguous()[None, :, :, :]
59
---> 60 self.set_torch_image(input_image_torch, image.shape[:2])
61
62 @torch.no_grad()

/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

/usr/local/lib/python3.10/dist-packages/segment_anything/predictor.py in set_torch_image(self, transformed_image, original_image_size)
80 len(transformed_image.shape) == 4
81 and transformed_image.shape[1] == 3
---> 82 and max(*transformed_image.shape[2:]) == self.model.image_encoder.img_size
83 ), f"set_torch_image input must be BCHW with long side {self.model.image_encoder.img_size}."
84 self.reset_image()

AssertionError: set_torch_image input must be BCHW with long side 1024.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.