segment-anything
segment-anything copied to clipboard
How do I feed batches to SamAutomaticMaskGenerator
I am not sure if this is available, but if it is, I'd love to know how to feed images in batches for SamAutomaticMaskGenerator
following
following
following
hi, you can feed a batch like this to the SAM image encoder with onnx runtime:
encoder_inputs = {"x": [batch[0,...].cpu().numpy(),
batch[1,...].cpu().numpy(),
batch[2,...].cpu().numpy()]
}
output = self.sam_encoder_session.run(None, encoder_inputs)
image_embedding = output[0]
decoder_inputs = {
"image_embeddings": image_embedding,
"point_coords": onnx_coord,
"point_labels": onnx_label,
"mask_input": onnx_mask_input,
"has_mask_input": onnx_has_mask_input,
"orig_im_size": np.array(image.shape[:2], dtype=np.float32)
}
I am using the onnx model for the encoder part taken from here
I just copy-pasted this code snippet from one of my projects but you can adjust it to your needs. Though I used this code to only get the image embeddings from the encoder and used my own decoder for something else. but it should work with the SAM default decoder as well to get the masks. The code's a bit messy but I was just playing around and haven't had the time to optimize it
following
https://github.com/ByungKwanLee/Full-Segment-Anything addresses the ciritical issues of SAM, which supports batch-input on the full-grid prompt (automatic mask generation) with post-processing: removing duplicated or small regions and holes, under flexible input image size