Skip to content

Commit

Permalink
restructure data
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhenyang (Daniel) Feng committed Jan 22, 2025
1 parent a7c1888 commit 8b231d7
Show file tree
Hide file tree
Showing 40 changed files with 156 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
__pycache__/
data/
out/
src/
GroundingDINO/
*.jpg
*.gif
*.png
*.pt
*.pth
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ To use SST, the following setup must be ran on a GPU enabled machine. The code r

Example Conda Environment Setup:
```bash
# clone repo
(git clone https://github.com/Imageomics/SST.git && cd SST)
# Create conda environment
conda create --name sst python=3.10.14
conda activate sst
# Download corresponding torch torchvision version
# Download PyTorch corresponding to the CUDA version of the GPU
...
# Download and setup GroundingDINO
(git clone https://github.com/IDEA-Research/GroundingDINO.git && cd GroundingDINO/ && pip install -e .)
# Download required python packages
pip install -r requirements.txt --no-dependencies
# Download model checkpoints
(cd checkpoints && ./download_ckpts.sh)
(cd checkpoints && wget -q https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth)
# Install SAM 2
(cd sam2 && pip install -e .)
(cd segment-anything-2 && pip install -e .)
```

## 🧑‍💻 Usage
Expand Down
2 changes: 1 addition & 1 deletion code/sam_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def show_anns(anns, color=None, borders=True):

ax.imshow(img)

def build_sam2_predictor(checkpoint="../../checkpoints/sam2_hiera_large.pt", model_cfg="../../sam2_configs/sam2_hiera_l.yaml"):
def build_sam2_predictor(checkpoint="checkpoints/sam2_hiera_large.pt", model_cfg="sam2_hiera_l"):
device = "cuda" if torch.cuda.is_available() else "cpu"
video_predictor = build_sam2_video_predictor(model_cfg, checkpoint, device=device, apply_postprocessing=False)
return video_predictor
Expand Down
8 changes: 6 additions & 2 deletions code/segment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#%%
import os
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -24,6 +23,7 @@
output_format = args.output_format

# load the support image and mask
print ("Loading support image and mask...")
support_image = cv2.imread(support_image_path)[..., ::-1]
support_mask = cv2.imread(support_mask_path, cv2.IMREAD_GRAYSCALE)
support_masks = [support_mask == i for i in range(1, support_mask.max()+1)]
Expand All @@ -36,11 +36,13 @@
video_predictor = sam_utils.build_sam2_predictor()

# load the support image and mask
print ("Inferring the masks...")
state = sam_utils.load_masks(video_predictor, query_images, support_image, support_masks, verbose=True)
frames_info = sam_utils.propagate_masks(video_predictor, state, verbose=True)

# visualize the results
output_imgs = []
print ("Visualizing the results...")
for i, frame in enumerate(frames_info):
plt.clf()
plt.figure(figsize=(10, 10))
Expand All @@ -61,8 +63,10 @@
if not os.path.exists(output_folder):
os.makedirs(output_folder)
if output_format == 'gif':
output_imgs[0].save(output_folder, save_all=True, append_images=output_imgs[1:], loop=0, duration=1000)
output_imgs[0].save(os.path.join(output_folder, "out.gif"), save_all=True, append_images=output_imgs[1:], loop=0, duration=1000)
else:
for i, img in enumerate(output_imgs):
img.save(os.path.join(output_folder, f"{i:06d}.png"))

print ("Done! The output is saved in", output_folder)

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ GitPython==3.1.43
google-pasta==0.2.0
gradio==3.32.0
gradio_client==0.2.5
-e git+https://github.com/IDEA-Research/GroundingDINO.git@856dde20aee659246248e20734ef9ba5214f5e44#egg=groundingdino
grpcio==1.66.1
h11==0.14.0
h5py==3.11.0
Expand Down
85 changes: 85 additions & 0 deletions segment-anything-2/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH, FOR_EACH_R, FOR_EACH_RANGE, ]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
24 changes: 24 additions & 0 deletions segment-anything-2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.vscode/
.DS_Store
__pycache__/
*-checkpoint.ipynb
.venv
*.egg*
build/*
_C.*
outputs/*
*.pt
*.sh
data/*
*.jpg
*.png
results/*
sav_dataset/*
*.gz
*.zip
*.out
*.log
*.pkl
*.pdf
*.gif

20 changes: 20 additions & 0 deletions segment-anything-2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2023-2024 Imageomics Institute

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions segment-anything-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SST

Repository for the paper Static Segmentation by Tracking: A Frustratingly Label-Efficient Approach to Fine-Grained Segmentation.
6 changes: 6 additions & 0 deletions segment-anything-2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=61.0",
"torch>=2.3.1",
]
build-backend = "setuptools.build_meta"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8b231d7

Please sign in to comment.