diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-28 15:14:55 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-28 15:14:55 +0200 |
commit | c032ffb05a7ed86f8fe5d596f94e8997c558cae8 (patch) | |
tree | bf890ffd4c815db7d510cfb281d253b5728f70c6 /text_recognizer/networks/util.py | |
parent | 524bf4351ac295bd4ff9914bb1f32eda7f7ff855 (diff) |
Reformatting with attrs, config for encoder and decoder
Diffstat (limited to 'text_recognizer/networks/util.py')
-rw-r--r-- | text_recognizer/networks/util.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/text_recognizer/networks/util.py b/text_recognizer/networks/util.py index 85094f1..e822c57 100644 --- a/text_recognizer/networks/util.py +++ b/text_recognizer/networks/util.py @@ -1,5 +1,7 @@ """Miscellaneous neural network utility functionality.""" -from typing import Type +from functools import partial +from importlib import import_module +from typing import Any, Type from torch import nn @@ -19,3 +21,9 @@ def activation_function(activation: str) -> Type[nn.Module]: ] ) return activation_fns[activation.lower()] + + +def load_partial_fn(fn: str, **kwargs: Any) -> partial: + """Loads partial function.""" + module = import_module(".".join(fn.split(".")[:-1])) + return partial(getattr(module, fn.split(".")[0]), **kwargs) |