Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

651 3d encoder support vit l and vit h #652

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions micro_sam/models/sam_3d_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,32 @@ def get_sam_3d_model(
lora_rank=lora_rank,
)

sam_3d = Sam3DWrapper(sam, freeze_encoder=freeze_encoder_)
sam_3d = Sam3DWrapper(sam, freeze_encoder=freeze_encoder_, model_type=model_type)
sam_3d.to(device)
return sam_3d


class Sam3DWrapper(nn.Module):
def __init__(self, sam_model: Sam, freeze_encoder: bool):
def __init__(self, sam_model: Sam, freeze_encoder: bool, model_type: str = "vit_b"):
"""Initializes the Sam3DWrapper object.

Args:
sam_model: The Sam model to be wrapped.
"""
super().__init__()
if model_type == "vit_b":
embed_dim = 768
num_heads = 12
elif model_type == "vit_l":
embed_dim = 1024
num_heads = 16
elif model_type == "vit_h":
embed_dim = 1280
num_heads = 16
sam_model.image_encoder = ImageEncoderViT3DWrapper(
image_encoder=sam_model.image_encoder
image_encoder=sam_model.image_encoder,
embed_dim=embed_dim,
num_heads=num_heads,
)
self.sam_model = sam_model

Expand Down
Loading