-
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
3473bb2
commit 2028879
Showing
5 changed files
with
593 additions
and
41 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from . import sweeps | ||
from . import train | ||
from . import eval | ||
from . import timm_huggingface |
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,32 @@ | ||
from transformers import PreTrainedModel, PretrainedConfig | ||
from transformers import AutoModel, AutoConfig | ||
import timm | ||
|
||
class ECAConfig(PretrainedConfig): | ||
model_type = 'mymodel' | ||
def __init__(self, model_name, **kwargs): | ||
super().__init__(**kwargs) | ||
self.model_name = model_name | ||
self.config = None | ||
|
||
class ECAModel(PreTrainedModel): | ||
config_class = ECAConfig | ||
def __init__(self, config): | ||
super().__init__(config) | ||
self.config = config | ||
self.model = timm.create_model(self.config.model_name, pretrained=True) | ||
self.config = self.model.default_cfg | ||
print(self.config) | ||
self.img_size = config["test_input_size"][-1] if "test_input_size" in config else config["input_size"][-1] | ||
|
||
def get_transform(self): | ||
return timm.data.transforms_factory.transforms_imagenet_eval( | ||
img_size=self.img_size, | ||
interpolation=self.config["interpolation"], | ||
mean=self.config["mean"], | ||
std=self.config["std"], | ||
crop_pct=self.config["crop_pct"], | ||
) | ||
|
||
def forward(self, input): | ||
return self.model(input) |
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.