-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added mobilesam model adapter; updated the two main widgets
- Loading branch information
Showing
16 changed files
with
179 additions
and
169 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/featureforest/SAM/models/weights/mobile_sam.pt.REMOVED.git-id
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 +1,13 @@ | ||
__version__ = "0.0.2" | ||
|
||
from ._embedding_extractor_widget import EmbeddingExtractorWidget | ||
from ._sam_predictor_widget import SAMPredictorWidget | ||
# from ._sam_predictor_widget import SAMPredictorWidget | ||
from ._sam_rf_segmentation_widget import SAMRFSegmentationWidget | ||
from ._sam_prompt_segmentation_widget import SAMPromptSegmentationWidget | ||
# from ._sam_prompt_segmentation_widget import SAMPromptSegmentationWidget | ||
|
||
__all__ = ( | ||
"EmbeddingExtractorWidget", | ||
"SAMPredictorWidget", | ||
# "SAMPredictorWidget", | ||
"SAMRFSegmentationWidget", | ||
"SAMPromptSegmentationWidget" | ||
# "SAMPromptSegmentationWidget" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .model import get_model | ||
from .adapter import MobileSAMAdapter |
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,52 @@ | ||
from typing import Tuple | ||
|
||
import torch | ||
import torch.nn as nn | ||
from torch import Tensor | ||
from torchvision.transforms import v2 as tv_transforms2 | ||
|
||
from featureforest.models.base import BaseModelAdapter | ||
from featureforest.utils.data import ( | ||
get_nonoverlapped_patches, | ||
) | ||
|
||
|
||
class MobileSAMAdapter(BaseModelAdapter): | ||
"""MobileSAM model adapter | ||
""" | ||
def __init__( | ||
self, | ||
model: nn.Module, | ||
input_transforms: tv_transforms2.Compose, | ||
patch_size: int, | ||
overlap: int, | ||
) -> None: | ||
super().__init__(model, input_transforms, patch_size, overlap) | ||
# we need sam image encoder part | ||
self.encoder = self.model.image_encoder | ||
self.encoder_num_channels = 256 | ||
self.embed_layer_num_channels = 64 | ||
|
||
def get_features_patches( | ||
self, in_patches: Tensor | ||
) -> Tuple[Tensor, Tensor]: | ||
# get the mobile-sam encoder and embedding layer outputs | ||
with torch.no_grad(): | ||
output, embed_output, _ = self.encoder( | ||
self.input_transforms(in_patches) | ||
) | ||
|
||
# get non-overlapped feature patches | ||
out_feature_patches = get_nonoverlapped_patches( | ||
self.embedding_transform(output.cpu()), | ||
self.patch_size, self.overlap | ||
) | ||
embed_feature_patches = get_nonoverlapped_patches( | ||
self.embedding_transform(embed_output.cpu()), | ||
self.patch_size, self.overlap | ||
) | ||
|
||
return out_feature_patches, embed_feature_patches | ||
|
||
def get_total_output_channels(self) -> int: | ||
return self.encoder_num_channels + self.embed_layer_num_channels |
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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.