-
Notifications
You must be signed in to change notification settings - Fork 4
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
90c9046
commit dfafc14
Showing
5 changed files
with
75 additions
and
10 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 +1 @@ | ||
7da60bb75eb45b3834f33479d4046ec7fab08345 | ||
db442d303be0dd469d9caa556f1fa6d6a93cbf89 |
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,26 @@ | ||
from typing import Any | ||
|
||
from todd.configs import PyConfig | ||
|
||
_kwargs_: dict[str, Any] | ||
_kwargs_ = dict(_kwargs_) | ||
|
||
_kwargs_.setdefault('branch', 'Global') | ||
_kwargs_.setdefault('strategy', 'cuda') | ||
|
||
_base_ = [ | ||
PyConfig.load('configs/oake/interface.py', **_kwargs_), | ||
] | ||
|
||
runner = dict( | ||
model=dict(type='ram_plus', expand_mask_size=None, adaptive=False), | ||
) | ||
custom_imports = [ | ||
'oadp.oake.globals_', | ||
] | ||
|
||
_export_ = dict( | ||
trainer=runner, | ||
validator=runner, | ||
custom_imports=custom_imports, | ||
) |
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,4 @@ | ||
from .clip import * | ||
from .dino import * | ||
from .expanders import * | ||
from .ram import * |
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,36 @@ | ||
__all__ = [ | ||
'ram_plus', | ||
] | ||
|
||
import todd.tasks.image_classification as ic | ||
import torch | ||
import torchvision.transforms.v2 as tf_v2 | ||
from todd.datasets import IMAGENET_MEAN, IMAGENET_STD | ||
from todd.tasks.image_classification.models.ram import Categories | ||
from torch import nn | ||
|
||
from ..registries import OAKEModelRegistry | ||
|
||
|
||
@OAKEModelRegistry.register_() | ||
def ram_plus( | ||
expand_mask_size: int | None, | ||
adaptive: bool, | ||
) -> tuple[nn.Module, tf_v2.Compose]: | ||
assert expand_mask_size is None | ||
assert not adaptive | ||
|
||
categories = Categories.load() | ||
model = ic.models.RAMplus(num_categories=len(categories)) | ||
model.load_pretrained('pretrained/ram/ram_plus_swin_large_14m.pth') | ||
model.requires_grad_(False) | ||
model.eval() | ||
|
||
transforms = tf_v2.Compose([ | ||
tf_v2.Resize((384, 384)), | ||
tf_v2.ToImage(), | ||
tf_v2.ToDtype(torch.float32, True), | ||
tf_v2.Normalize(IMAGENET_MEAN, IMAGENET_STD), | ||
]) | ||
|
||
return model, transforms |