Port SAM3 from inference/models to inference-models#1946
Port SAM3 from inference/models to inference-models#1946grzegorz-roboflow wants to merge 6 commits intomainfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
|
||
|
|
||
| def pad_points(args: Dict) -> Dict: | ||
| args = copy(args) |
There was a problem hiding this comment.
Shallow copy instead of deep copy mutates caller's data
High Severity
The pad_points function uses copy(args) (shallow copy) instead of copy.deepcopy(args) as in the original implementation. Since the function mutates nested lists via prompt.append([0, 0]) and label.append(-1), the caller's original point_coords and point_labels data structures are modified unexpectedly. This causes data corruption when the same input data is reused across multiple calls.
| else np_image | ||
| ) | ||
| else: | ||
| np_image = image |
There was a problem hiding this comment.
Numpy arrays not normalized like tensor inputs in embedding
Medium Severity
In _forward_image_embeddings, numpy arrays are used directly without the CHW-to-HWC transposition or 0-1 to 0-255 normalization that tensor inputs receive. However, segment_with_text applies both transformations to numpy and tensor inputs alike. This inconsistency means a float numpy array with values in [0,1] or CHW layout will produce incorrect embeddings when using embed_images/segment_images, but work correctly in segment_with_text.
| f"error running on Roboflow platform - contact us to get help.", | ||
| help_url="https://todo", | ||
| ) | ||
| while len(self._state) > self._size_limit: |
There was a problem hiding this comment.
Cache capacity check allows exceeding size limit
Low Severity
The _ensure_cache_has_capacity method uses while len(...) > self._size_limit but is called BEFORE adding a new item. This means when the cache has exactly size_limit items, nothing is removed, and the subsequent add causes the cache to exceed its limit by one item. The condition needs >= instead of > to properly make room before adding.
What does this PR do?
Add SAM3 to inference-models
Type of Change
Testing
Added integration tests to cover SAM3
Checklist
Additional Context
N/A
Note
Introduces SAM3 (Segment Anything 3) to
inference-modelswith a PyTorch wrapper and caching utilities.SAM3Torchwith image embedding, point/box prompting, mask-input refinement, and text/visual prompting APIs; supports batching, logits return, and version validationSAM3ImageEmbeddings,SAM3Prediction,SAM3MaskCacheEntry) and helpers (prompt serialization, mask selection, hashing)README.md) with usage examples and aLICENSE.txtfor SAM3pyproject.tomlto includesam3and platform-conditionaltritondepsvisual_segmentation.pyto short-circuit cache search when prompt has ≤1 pointWritten by Cursor Bugbot for commit bb1a8a2. This will update automatically on new commits. Configure here.