-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
encoder
flexibility in UNETR (#10)
* Update distance transform (#11 - Getting instance segmentations from the distance transform) * Making the encoder argument flexible (to either pytorch modules or model name as str)
- Loading branch information
Showing
3 changed files
with
80 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import torch | ||
|
||
from torch_em.model import UNETR | ||
|
||
from micro_sam.util import get_sam_model | ||
|
||
|
||
def main(): | ||
checkpoint = "/scratch/usr/nimanwai/models/segment-anything/checkpoints/sam_vit_b_01ec64.pth" | ||
model_type = "vit_b" | ||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
|
||
predictor = get_sam_model( | ||
model_type=model_type, | ||
checkpoint_path=checkpoint | ||
) | ||
|
||
model = UNETR( | ||
backbone="sam", | ||
encoder=predictor.model.image_encoder, | ||
out_channels=3, | ||
use_sam_stats=True, | ||
final_activation="Sigmoid", | ||
use_skip_connection=False | ||
) | ||
model.to(device) | ||
|
||
x = torch.ones((1, 1, 512, 512)).to(device) | ||
y = model(x) | ||
|
||
print("UNETR Model successfully created and encoder initialized from", checkpoint) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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