Commit Graph

200 Commits

Author SHA1 Message Date
rentainhe
8b56c25344 update to latest sam2 2024-12-21 11:21:48 +08:00
Ronghang Hu
2b90b9f5ce remove .pin_memory() in obj_pos of SAM2Base to resolve and error in MPS (#495)
In this PR, we remove `.pin_memory()` in `obj_pos` of `SAM2Base` to resolve and error in MPS. Investigations show that `.pin_memory()` causes an error of `Attempted to set the storage of a tensor on device "cpu" to a storage on different device "mps:0"`, as originally reported in https://github.com/facebookresearch/sam2/issues/487.

(close https://github.com/facebookresearch/sam2/issues/487)
2024-12-15 16:47:17 -08:00
Ronghang Hu
722d1d1511 patch for the case of offload_state_to_cpu=True in the new SAM2VideoPredictor (#490)
This PR adds a pathc for the case of `offload_state_to_cpu=True` where `pred_masks` might have been offload to CPU device (close https://github.com/facebookresearch/sam2/issues/489)
2024-12-12 15:12:13 -08:00
Ronghang Hu
393ae336a7 SAM 2 Update 12/11/2024 -- full model compilation for a major VOS speedup and a new SAM2VideoPredictor to better handle multi-object tracking (#486)
This PR provides new features and updates for SAM 2:

- We now support `torch.compile` of the entire SAM 2 model on videos, which can be turned on by setting `vos_optimized=True` in `build_sam2_video_predictor` (it uses the new `SAM2VideoPredictorVOS` predictor class in `sam2/sam2_video_predictor.py`).
  * Compared to the previous setting (which only compiles the image encoder backbone), the new full model compilation gives a major speedup in inference FPS.
  * In the VOS prediction script `tools/vos_inference.py`, you can specify this option in `tools/vos_inference.py` via the `--use_vos_optimized_video_predictor` flag.
  * Note that turning on this flag might introduce a small variance in the predictions due to numerical differences caused by `torch.compile` of the full model.
  * **PyTorch 2.5.1 is the minimum version for full support of this feature**. (Earlier PyTorch versions might run into compilation errors in some cases.) Therefore, we have updated the minimum PyTorch version to 2.5.1 accordingly in the installation scripts.
- We also update the implementation of the `SAM2VideoPredictor` class for the SAM 2 video prediction in `sam2/sam2_video_predictor.py`, which allows for independent per-object inference. Specifically, in the new `SAM2VideoPredictor`:
  * Now **we handle the inference of each object independently** (as if we are opening a separate session for each object) while sharing their backbone features.
  * This change allows us to relax the assumption of prompting for multi-object tracking. Previously (due to the batching behavior in inference), if a video frame receives clicks for only a subset of objects, the rest of the (non-prompted) objects are assumed to be non-existent in this frame (i.e., in such frames, the user is telling SAM 2 that the rest of the objects don't appear). Now, if a frame receives clicks for only a subset of objects, we do not make any assumptions about the remaining (non-prompted) objects (i.e., now each object is handled independently and is not affected by how other objects are prompted). As a result, **we allow adding new objects after tracking starts** after this change (which was previously a restriction on usage).
  * We believe that the new version is a more natural inference behavior and therefore switched to it as the default behavior. The previous implementation of `SAM2VideoPredictor` is backed up to in `sam2/sam2_video_predictor_legacy.py`. All the VOS inference results using `tools/vos_inference.py` should remain the same after this change to the `SAM2VideoPredictor` class.
2024-12-11 15:00:55 -08:00
rentainhe
dd4c5141b7 update README v1.0 2024-12-09 11:35:16 +08:00
rentainhe
53dcb96024 Merge branch 'main' of github.com:IDEA-Research/Grounded-SAM-2 into main 2024-12-05 17:44:07 +08:00
rentainhe
87b1cb4e79 update dds-cloudapi-sdk to 0.3.3 2024-12-05 17:43:56 +08:00
Ren Tianhe
411f157507 Fix typo 2024-12-04 12:49:32 +08:00
rentainhe
de62b7fb0b add dino-x sam2 tracking demo 2024-12-02 21:01:55 +08:00
rentainhe
779147bc48 support DINO-X with SAM 2 for detection and segmentation 2024-12-02 19:43:59 +08:00
Ren Tianhe
13d23efc55 Add DINO-X arXiv link 2024-12-02 16:21:45 +08:00
John Heilman
7262a579d7 Fixed Type on MORE_DETAILED_CAPTION (#68) 2024-11-03 11:09:14 +08:00
rentainhe
91c69d763f Merge branch 'main' of github.com:IDEA-Research/Grounded-SAM-2 into main 2024-10-31 15:50:31 +08:00
rentainhe
1aec7ded16 support box threshold in GD 1.5 demos 2024-10-31 15:50:14 +08:00
Susan Shen
bf57b3086c fix: zero object detection error (#64)
* update dockerfile

* fix: zero object detection error

* fix: zero object detection error
2024-10-30 20:38:30 +08:00
rentainhe
e537a1e763 refine useless code 2024-10-30 11:25:19 +08:00
rentainhe
f776d247b9 refine README 2024-10-29 10:43:26 +08:00
rentainhe
5a44fe1889 refine README 2024-10-29 10:39:57 +08:00
rentainhe
fb875add87 refine README 2024-10-29 10:39:29 +08:00
rentainhe
3ef929186b refine README 2024-10-29 10:34:51 +08:00
rentainhe
d608a9adad update README for SAHI inference 2024-10-24 17:24:12 +08:00
rentainhe
041bb0bfa4 support slice inference on gd1.5 sam2 demo 2024-10-24 16:57:04 +08:00
rentainhe
be550a93b1 update running info 2024-10-23 11:27:18 +08:00
rentainhe
5abc04b713 update README 2024-10-18 16:21:32 +08:00
rentainhe
20dd89b60e fix hyper link for florence-2 demo 2024-10-16 15:26:13 +08:00
rentainhe
5c6166fb7e refine config 2024-10-15 12:17:53 +08:00
Haitham Khedr
c2ec8e14a1 remove unused paths (#384) 2024-10-14 10:40:54 -04:00
Ren Tianhe
82e503604f [New Feature] Support SAM 2.1 (#59)
* support sam 2.1

* refine config path and ckpt path

* update README
2024-10-10 14:55:50 +08:00
Roman Rädle
c98aa6bea3 Merge pull request #364 from facebookresearch/pr364
[sam2][demo][1/x] Fix file upload

Summary:

The Strawberry GraphQL library recently disabled multipart requests by default. This resulted in a video upload request returning "Unsupported content type" instead of uploading the video, processing it, and returning the video path.

This issue was raised in #361. A forward fix is to add `multipart_uploads_enabled=True` to the endpoint view.

Test Plan:

Tested locally with cURL and upload succeeds

*Request*

```
curl http://localhost:7263/graphql \
  -F operations='{ "query": "mutation($file: Upload!){ uploadVideo(file: $file) { path } }", "variables": { "file": null } }' \
  -F map='{ "file": ["variables.file"] }' \
  -F file=@video.mov
```

*Response*

```
{"data": {"uploadVideo": {"path": "uploads/<HASH>.mp4"}}}
```
2024-10-08 15:28:14 -07:00
Roman Rädle
ff9704fc0e [sam2][demo][1/x] Fix file upload
Summary:

The Strawberry GraphQL library recently disabled multipart requests by default. This resulted in a video upload request returning "Unsupported content type" instead of uploading the video, processing it, and returning the video path.

This issue was raised in #361. A forward fix is to add `multipart_uploads_enabled=True` to the endpoint view.

Test Plan:

Tested locally with cURL and upload succeeds

*Request*

```
curl http://localhost:7263/graphql \
  -F operations='{ "query": "mutation($file: Upload!){ uploadVideo(file: $file) { path } }", "variables": { "file": null } }' \
  -F map='{ "file": ["variables.file"] }' \
  -F file=@video.mov
```

*Response*

```
{"data": {"uploadVideo": {"path": "uploads/<HASH>.mp4"}}}
```
2024-10-08 14:58:28 -07:00
Ronghang Hu
29267c8e39 [doc] Check and raise an error if the user is running Python from the parent directory of the sam2 repo (#359)
If the user has "sam2/sam2" in their path, they are likey importing the repo itself as "sam2" rather than importing the "sam2" python package (i.e. "sam2/sam2" directory). This typically happens because the user is running Python from the parent directory that contains the sam2 repo they cloned.

In general, the user should not run Python from the parent dir when the repo is cloned into (same is true for e.g. Numpy repo that contains names like `numpy/numpy` where the module and the repo have the same name), as the user encountered in https://github.com/facebookresearch/sam2/issues/346.

(close https://github.com/facebookresearch/sam2/issues/346)
2024-10-05 00:34:06 -07:00
Ronghang Hu
e22521832f [demo] add GPU to resources (#355)
This small PR adds GPU specification in `docker-compose.yaml` for the SAM 2 interactive webdemo, following https://docs.docker.com/compose/how-tos/gpu-support/#example-of-a-compose-file-for-running-a-service-with-access-to-1-gpu-device. It fixes a GPU access error as reported in https://github.com/facebookresearch/sam2/issues/354.

(close https://github.com/facebookresearch/sam2/issues/354)
2024-10-03 16:48:56 -07:00
Haitham Khedr
8bf0920e66 Add MANIFEST.in (#353) 2024-10-03 10:40:13 -07:00
Haitham Khedr
52198ead0e Merge pull request #2 from kit1980/patch-1
Use `weights_only` for loading
2024-10-01 22:32:58 +02:00
Ronghang Hu
98fcb164bf Update links after renaming the repo from segment-anything-2 to sam2 (#341)
This PR update repo links after we renamed the repo from `segment-anything-2` to `sam2`. It also changes `NAME` in setup.py to `SAM-2` (which is already the named used in pip setup since python packages don't allow whitespace)
2024-09-30 20:27:44 -07:00
Ronghang Hu
05d9e57fb3 [docs] add a release note and new installation instructions for SAM 2.1 (#338) 2024-09-30 09:55:58 -07:00
Ronghang Hu
429a2c7360 minor update README.md 2024-09-28 23:32:25 -07:00
Chay Ryali
3a7889d905 Merge pull request #335 from facebookresearch/sam2.1
SAM 2.1
2024-09-28 23:01:29 -07:00
Haitham Khedr
aa9b8722d0 SAM2.1
SAM2.1 checkpoints + training code + Demo
2024-09-29 05:49:56 +00:00
kwikwag
e899ad99e8 feat: grounded_sam2_hf_mode cli arguments (#52) 2024-09-24 20:33:11 +08:00
Susan Shen
81ac531aa9 update dockerfile (#47) 2024-09-06 20:44:58 +08:00
rentainhe
379e35cb40 support custom video tracking demo with local gd1.0 model 2024-09-05 14:57:17 +08:00
rentainhe
834de442cb update README for results format 2024-09-04 01:28:18 +08:00
Ren Tianhe
5ee7526b79 Merge pull request #42 from Greywan/dev
fix:fixed interruptions when there is no mask result for the current …
2024-09-03 16:07:00 +08:00
wanjunhui1
f3d381901a fix:fixed interruptions when there is no mask result for the current frame 2024-09-03 15:32:38 +08:00
Ren Tianhe
be1fa537bb Merge pull request #40 from IDEA-Research/dump_json_results
[Update] Support automatically dumping json results in image demos
2024-08-31 20:58:49 +08:00
rentainhe
daf5bb3f97 support dump results in local demo 2024-08-31 20:58:37 +08:00
rentainhe
e0daab208a support dump results in local demo 2024-08-31 20:55:49 +08:00
rentainhe
a99354bb25 add dump results to hf model demo 2024-08-31 20:40:59 +08:00
rentainhe
4f3adf3222 support dump results in 1.5 image demo 2024-08-31 20:22:17 +08:00