-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0d43f3
commit a461a76
Showing
9 changed files
with
300 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
checkpoints/ | ||
checkpoints/*.pt | ||
saved_engines/ | ||
output/ | ||
*.jpg | ||
bedroom/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tripy/examples/segment-anything-model-v2/checkpoints/download_ckpt.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
if command -v wget &> /dev/null; then | ||
CMD="wget" | ||
elif command -v curl &> /dev/null; then | ||
CMD="curl -L -O" | ||
else | ||
echo "Please install wget or curl to download the checkpoints." | ||
exit 1 | ||
fi | ||
|
||
SAM2p1_BASE_URL="https://dl.fbaipublicfiles.com/segment_anything_2/092824" | ||
sam2p1_hiera_t_url="${SAM2p1_BASE_URL}/sam2.1_hiera_tiny.pt" | ||
sam2p1_hiera_s_url="${SAM2p1_BASE_URL}/sam2.1_hiera_small.pt" | ||
sam2p1_hiera_l_url="${SAM2p1_BASE_URL}/sam2.1_hiera_large.pt" | ||
|
||
echo "Downloading sam2.1_hiera_tiny.pt checkpoint..." | ||
$CMD $sam2p1_hiera_t_url || { echo "Failed to download checkpoint from $sam2p1_hiera_t_url"; exit 1; } | ||
|
||
echo "Downloading sam2.1_hiera_small.pt checkpoint..." | ||
$CMD $sam2p1_hiera_s_url || { echo "Failed to download checkpoint from $sam2p1_hiera_s_url"; exit 1; } | ||
|
||
echo "Downloading sam2.1_hiera_large.pt checkpoint..." | ||
$CMD $sam2p1_hiera_l_url || { echo "Failed to download checkpoint from $sam2p1_hiera_l_url"; exit 1; } |
116 changes: 116 additions & 0 deletions
116
tripy/examples/segment-anything-model-v2/configs/sam2_hiera_s.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# @package _global_ | ||
|
||
# Model | ||
model: | ||
_target_: sam2.modeling.sam2_base.SAM2Base | ||
image_encoder: | ||
_target_: sam2.modeling.backbones.image_encoder.ImageEncoder | ||
scalp: 1 | ||
trunk: | ||
_target_: sam2.modeling.backbones.hieradet.Hiera | ||
embed_dim: 96 | ||
num_heads: 1 | ||
stages: [1, 2, 11, 2] | ||
global_att_blocks: [7, 10, 13] | ||
window_pos_embed_bkg_spatial_size: [7, 7] | ||
block_pad_size: [0, 0, 0 ,0, 6, 6, 6, 0, 6, 6, 0, 6, 6, 0, 6, 3] | ||
block_unpad_size: [0, 0, 0, 0, 64, 64, 64, 0, 64, 64, 0, 64, 64, 0, 32, 32] | ||
dtype: float16 | ||
neck: | ||
_target_: sam2.modeling.backbones.image_encoder.FpnNeck | ||
position_encoding: | ||
_target_: sam2.modeling.position_encoding.PositionEmbeddingSine | ||
num_pos_feats: 256 | ||
normalize: true | ||
scale: null | ||
temperature: 10000 | ||
d_model: 256 | ||
backbone_channel_list: [768, 384, 192, 96] | ||
fpn_top_down_levels: [2, 3] # output level 0 and 1 directly use the backbone features | ||
fpn_interp_model: nearest | ||
dtype: float16 | ||
|
||
memory_attention: | ||
_target_: sam2.modeling.memory_attention.MemoryAttention | ||
d_model: 256 | ||
pos_enc_at_input: true | ||
dtype: float16 | ||
num_layers: 4 | ||
# memory attention layer | ||
activation: relu | ||
dim_feedforward: 2048 | ||
dropout: 0.1 | ||
pos_enc_at_attn: false | ||
pos_enc_at_cross_attn_keys: true | ||
pos_enc_at_cross_attn_queries: false | ||
# self rope attention | ||
sa_rope_theta: 10000.0 | ||
sa_feat_sizes: [64, 64] | ||
sa_embedding_dim: 256 | ||
sa_num_heads: 1 | ||
sa_downsample_rate: 1 | ||
sa_dropout: 0.1 | ||
# cross rope attention | ||
ca_rope_theta: 10000.0 | ||
ca_feat_sizes: [64, 64] | ||
ca_rope_k_repeat: True | ||
ca_embedding_dim: 256 | ||
ca_num_heads: 1 | ||
ca_downsample_rate: 1 | ||
ca_dropout: 0.1 | ||
ca_kv_in_dim: 64 | ||
|
||
memory_encoder: | ||
_target_: sam2.modeling.memory_encoder.MemoryEncoder | ||
out_dim: 64 | ||
position_encoding: | ||
_target_: sam2.modeling.position_encoding.PositionEmbeddingSine | ||
num_pos_feats: 64 | ||
normalize: true | ||
scale: null | ||
temperature: 10000 | ||
mask_downsampler: | ||
_target_: sam2.modeling.memory_encoder.MaskDownSampler | ||
kernel_size: 3 | ||
stride: 2 | ||
padding: 1 | ||
fuser: | ||
_target_: sam2.modeling.memory_encoder.Fuser | ||
layer: | ||
_target_: sam2.modeling.memory_encoder.CXBlock | ||
dim: 256 | ||
kernel_size: 7 | ||
padding: 3 | ||
layer_scale_init_value: 1e-6 | ||
use_dwconv: True # depth-wise convs | ||
num_layers: 2 | ||
|
||
num_maskmem: 7 | ||
image_size: 1024 | ||
# apply scaled sigmoid on mask logits for memory encoder, and directly feed input mask as output mask | ||
sigmoid_scale_for_mem_enc: 20.0 | ||
sigmoid_bias_for_mem_enc: -10.0 | ||
use_mask_input_as_output_without_sam: true | ||
# Memory | ||
directly_add_no_mem_embed: true | ||
# use high-resolution feature map in the SAM mask decoder | ||
use_high_res_features_in_sam: true | ||
# output 3 masks on the first click on initial conditioning frames | ||
multimask_output_in_sam: true | ||
# SAM heads | ||
iou_prediction_use_sigmoid: True | ||
# cross-attend to object pointers from other frames (based on SAM output tokens) in the encoder | ||
use_obj_ptrs_in_encoder: true | ||
add_tpos_enc_to_obj_ptrs: false | ||
only_obj_ptrs_in_the_past_for_eval: true | ||
# object occlusion prediction | ||
pred_obj_scores: true | ||
pred_obj_scores_mlp: true | ||
fixed_no_obj_ptr: true | ||
# multimask tracking settings | ||
multimask_output_for_tracking: true | ||
use_multimask_token_for_obj_ptr: true | ||
multimask_min_pt_num: 0 | ||
multimask_max_pt_num: 1 | ||
use_mlp_for_obj_ptr_proj: true | ||
model_precision: float16 |
116 changes: 116 additions & 0 deletions
116
tripy/examples/segment-anything-model-v2/configs/sam2_hiera_t.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# @package _global_ | ||
|
||
# Model | ||
model: | ||
_target_: sam2.modeling.sam2_base.SAM2Base | ||
image_encoder: | ||
_target_: sam2.modeling.backbones.image_encoder.ImageEncoder | ||
scalp: 1 | ||
trunk: | ||
_target_: sam2.modeling.backbones.hieradet.Hiera | ||
embed_dim: 96 | ||
num_heads: 1 | ||
stages: [1, 2, 7, 2] | ||
global_att_blocks: [5, 7, 9] | ||
window_pos_embed_bkg_spatial_size: [7, 7] | ||
block_pad_size: [0, 0, 0 ,0, 6, 0, 6, 0, 6, 0, 6, 3] | ||
block_unpad_size: [0, 0, 0, 0, 64, 0, 64, 0, 64, 0, 32, 32] | ||
dtype: float16 | ||
neck: | ||
_target_: sam2.modeling.backbones.image_encoder.FpnNeck | ||
position_encoding: | ||
_target_: sam2.modeling.position_encoding.PositionEmbeddingSine | ||
num_pos_feats: 256 | ||
normalize: true | ||
scale: null | ||
temperature: 10000 | ||
d_model: 256 | ||
backbone_channel_list: [768, 384, 192, 96] | ||
fpn_top_down_levels: [2, 3] # output level 0 and 1 directly use the backbone features | ||
fpn_interp_model: nearest | ||
dtype: float16 | ||
|
||
memory_attention: | ||
_target_: sam2.modeling.memory_attention.MemoryAttention | ||
d_model: 256 | ||
pos_enc_at_input: true | ||
dtype: float16 | ||
num_layers: 4 | ||
# memory attention layer | ||
activation: relu | ||
dim_feedforward: 2048 | ||
dropout: 0.1 | ||
pos_enc_at_attn: false | ||
pos_enc_at_cross_attn_keys: true | ||
pos_enc_at_cross_attn_queries: false | ||
# self rope attention | ||
sa_rope_theta: 10000.0 | ||
sa_feat_sizes: [64, 64] | ||
sa_embedding_dim: 256 | ||
sa_num_heads: 1 | ||
sa_downsample_rate: 1 | ||
sa_dropout: 0.1 | ||
# cross rope attention | ||
ca_rope_theta: 10000.0 | ||
ca_feat_sizes: [64, 64] | ||
ca_rope_k_repeat: True | ||
ca_embedding_dim: 256 | ||
ca_num_heads: 1 | ||
ca_downsample_rate: 1 | ||
ca_dropout: 0.1 | ||
ca_kv_in_dim: 64 | ||
|
||
memory_encoder: | ||
_target_: sam2.modeling.memory_encoder.MemoryEncoder | ||
out_dim: 64 | ||
position_encoding: | ||
_target_: sam2.modeling.position_encoding.PositionEmbeddingSine | ||
num_pos_feats: 64 | ||
normalize: true | ||
scale: null | ||
temperature: 10000 | ||
mask_downsampler: | ||
_target_: sam2.modeling.memory_encoder.MaskDownSampler | ||
kernel_size: 3 | ||
stride: 2 | ||
padding: 1 | ||
fuser: | ||
_target_: sam2.modeling.memory_encoder.Fuser | ||
layer: | ||
_target_: sam2.modeling.memory_encoder.CXBlock | ||
dim: 256 | ||
kernel_size: 7 | ||
padding: 3 | ||
layer_scale_init_value: 1e-6 | ||
use_dwconv: True # depth-wise convs | ||
num_layers: 2 | ||
|
||
num_maskmem: 7 | ||
image_size: 1024 | ||
# apply scaled sigmoid on mask logits for memory encoder, and directly feed input mask as output mask | ||
sigmoid_scale_for_mem_enc: 20.0 | ||
sigmoid_bias_for_mem_enc: -10.0 | ||
use_mask_input_as_output_without_sam: true | ||
# Memory | ||
directly_add_no_mem_embed: true | ||
# use high-resolution feature map in the SAM mask decoder | ||
use_high_res_features_in_sam: true | ||
# output 3 masks on the first click on initial conditioning frames | ||
multimask_output_in_sam: true | ||
# SAM heads | ||
iou_prediction_use_sigmoid: True | ||
# cross-attend to object pointers from other frames (based on SAM output tokens) in the encoder | ||
use_obj_ptrs_in_encoder: true | ||
add_tpos_enc_to_obj_ptrs: false | ||
only_obj_ptrs_in_the_past_for_eval: true | ||
# object occlusion prediction | ||
pred_obj_scores: true | ||
pred_obj_scores_mlp: true | ||
fixed_no_obj_ptr: true | ||
# multimask tracking settings | ||
multimask_output_for_tracking: true | ||
use_multimask_token_for_obj_ptr: true | ||
multimask_min_pt_num: 0 | ||
multimask_max_pt_num: 1 | ||
use_mlp_for_obj_ptr_proj: true | ||
model_precision: float16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.