-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tailor): add high-level framework-agnostic convert (#97)
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 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,46 @@ | ||
from typing import overload, Optional, Tuple | ||
|
||
from ..helper import get_framework, AnyDNN | ||
|
||
|
||
# Keras Tailor | ||
@overload | ||
def convert( | ||
model: AnyDNN, | ||
freeze: bool = False, | ||
embedding_layer_name: Optional[str] = None, | ||
output_dim: Optional[int] = None, | ||
) -> AnyDNN: | ||
... | ||
|
||
|
||
# Pytorch and Paddle Tailor | ||
@overload | ||
def convert( | ||
model: AnyDNN, | ||
input_size: Tuple[int, ...], | ||
freeze: bool = False, | ||
embedding_layer_name: Optional[str] = None, | ||
output_dim: Optional[int] = None, | ||
input_dtype: str = 'float32', | ||
) -> AnyDNN: | ||
... | ||
|
||
|
||
def convert(model: AnyDNN, **kwargs) -> AnyDNN: | ||
f_type = get_framework(model) | ||
|
||
if f_type == 'keras': | ||
from .keras import KerasTailor | ||
|
||
ft = KerasTailor | ||
elif f_type == 'torch': | ||
from .pytorch import PytorchTailor | ||
|
||
ft = PytorchTailor | ||
elif f_type == 'paddle': | ||
from .paddle import PaddleTailor | ||
|
||
ft = PaddleTailor | ||
|
||
return ft(model, **kwargs)().model |