Update README.md with new model card content
Browse files
README.md
CHANGED
|
@@ -1,16 +1,89 @@
|
|
| 1 |
---
|
| 2 |
library_name: keras-hub
|
| 3 |
---
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: keras-hub
|
| 3 |
---
|
| 4 |
+
### Model Overview
|
| 5 |
+
# SAM 3
|
| 6 |
+
|
| 7 |
+
The Segment Anything Model 3 (SAM 3) is a high-performance foundation model for promptable object segmentation in images. Building upon the breakthroughs of previous SAM iterations, SAM 3 is designed for real-time performance, superior mask quality, and improved zero-shot generalization across diverse visual domains.
|
| 8 |
+
|
| 9 |
+
## Model Summary
|
| 10 |
+
|
| 11 |
+
SAM 3 follows the "Segment Anything" philosophy by providing a universal interface for segmentation via prompts such as points, bounding boxes, or previous masks. It features a decoupled architecture that separates heavy image encoding from lightweight prompt processing, allowing the model to generate masks in near real-time once an image embedding has been computed.
|
| 12 |
+
|
| 13 |
+
SAM3 promptable concept segmentation (PCS) segments objects in images based
|
| 14 |
+
on concept prompts, which could be short noun phrases (e.g., “yellow school bus”), image exemplars, or a combination of both. SAM3 PCS takes such prompts and returns segmentation masks and unique identities for all matching object instances.
|
| 15 |
+
|
| 16 |
+
There are two ways to prompt:
|
| 17 |
+
1. Text prompt: A short noun phrase describing the concept to segment.
|
| 18 |
+
2. Box prompt: A box tells the model which part/crop of the image to
|
| 19 |
+
segment.
|
| 20 |
+
|
| 21 |
+
These prompts can be used individually or together, but at least one of the prompts must be present. To turn off a particular prompt, simply exclude it from the inputs to the model.
|
| 22 |
+
|
| 23 |
+
This modular design allows users to swap backbones of varying sizes (Tiny, Small, Base, Large) depending on the hardware constraints and accuracy requirements.
|
| 24 |
+
|
| 25 |
+
## References
|
| 26 |
+
|
| 27 |
+
* [SAM 3 Quickstart Notebook](Coming Soon)
|
| 28 |
+
* [SAM 3 API Documentation](https://keras.io/keras_hub/api/models/sam3/)
|
| 29 |
+
* [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
|
| 30 |
+
* [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
|
| 31 |
+
* [Segment Anything 3 Technical Report](https://huggingface.co/facebook/sam3)
|
| 32 |
+
|
| 33 |
+
## Installation
|
| 34 |
+
|
| 35 |
+
Keras and KerasHub can be installed using the following commands:
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
pip install -U -q keras-hub
|
| 39 |
+
pip install -U -q keras
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
The following table summarizes the different configurations available for SAM 3 in Keras Hub:
|
| 43 |
+
|
| 44 |
+
| Preset | Parameters | Description |
|
| 45 |
+
| ---------------------------- | ---------- | ------------------------------------------------------------------------------------------------ |
|
| 46 |
+
| `sam3_pcs` | ~30M | Promptable Concept Segmentation (PCS) SAM model|
|
| 47 |
+
|
| 48 |
+
## Example Usage
|
| 49 |
+
```python
|
| 50 |
+
image_size = 128
|
| 51 |
+
batch_size = 2
|
| 52 |
+
input_data = {
|
| 53 |
+
"images": np.ones(
|
| 54 |
+
(batch_size, image_size, image_size, 3), dtype="float32",
|
| 55 |
+
),
|
| 56 |
+
"prompts": ["ear", "head"],
|
| 57 |
+
"boxes": np.ones((batch_size, 1, 4), dtype="float32"), # XYXY format.
|
| 58 |
+
"box_labels": np.ones((batch_size, 1), dtype="float32"),
|
| 59 |
+
}
|
| 60 |
+
sam3_pcs = keras_hub.models.SAM3PromptableConceptImageSegmenter.from_preset(
|
| 61 |
+
"sam3_pcs"
|
| 62 |
+
)
|
| 63 |
+
outputs = sam3_pcs.predict(input_data)
|
| 64 |
+
scores = outputs["scores"] # [B, num_queries]
|
| 65 |
+
boxes = outputs["boxes"] # [B, num_queries, 4]
|
| 66 |
+
masks = outputs["masks"] # [B, num_queries, H, W]
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Example Usage with Hugging Face URI
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
image_size = 128
|
| 73 |
+
batch_size = 2
|
| 74 |
+
input_data = {
|
| 75 |
+
"images": np.ones(
|
| 76 |
+
(batch_size, image_size, image_size, 3), dtype="float32",
|
| 77 |
+
),
|
| 78 |
+
"prompts": ["ear", "head"],
|
| 79 |
+
"boxes": np.ones((batch_size, 1, 4), dtype="float32"), # XYXY format.
|
| 80 |
+
"box_labels": np.ones((batch_size, 1), dtype="float32"),
|
| 81 |
+
}
|
| 82 |
+
hf://keras/sam3_pcs = keras_hub.models.SAM3PromptableConceptImageSegmenter.from_preset(
|
| 83 |
+
"hf://keras/sam3_pcs"
|
| 84 |
+
)
|
| 85 |
+
outputs = hf://keras/sam3_pcs.predict(input_data)
|
| 86 |
+
scores = outputs["scores"] # [B, num_queries]
|
| 87 |
+
boxes = outputs["boxes"] # [B, num_queries, 4]
|
| 88 |
+
masks = outputs["masks"] # [B, num_queries, H, W]
|
| 89 |
+
```
|