Skip to content

Instantly share code, notes, and snippets.

@rekalantar
Last active May 30, 2023 10:26
Show Gist options
  • Select an option

  • Save rekalantar/ee86617125f15a97e1660d544e2807e5 to your computer and use it in GitHub Desktop.

Select an option

Save rekalantar/ee86617125f15a97e1660d544e2807e5 to your computer and use it in GitHub Desktop.
# load the pretrained weights for finetuning
model = SamModel.from_pretrained("facebook/sam-vit-base")
# make sure we only compute gradients for mask decoder (encoder weights are frozen)
for name, param in model.named_parameters():
if name.startswith("vision_encoder") or name.startswith("prompt_encoder"):
param.requires_grad_(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment