diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-06-26 00:35:02 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-06-26 00:35:02 +0200 |
commit | 22e36513dd43d2e2ca82ca28a1ea757c5663676a (patch) | |
tree | 54285c3c30a02b00af989078bf61c122b9eccabd /text_recognizer/models | |
parent | 9c3a8753d95ecb70a84e1eb40933590a510abfc4 (diff) |
Updates
Diffstat (limited to 'text_recognizer/models')
-rw-r--r-- | text_recognizer/models/dino.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/text_recognizer/models/dino.py b/text_recognizer/models/dino.py new file mode 100644 index 0000000..dca954c --- /dev/null +++ b/text_recognizer/models/dino.py @@ -0,0 +1,28 @@ +"""Dino: pretraining of models with self supervision.""" +import copy +from functools import wraps, partial + +import torch +from torch import nn +import torch.nn.funtional as F +import torchvision.transforms as T +import wandb + +from text_recognizer.models.base import LitBaseModel + + +def singleton(cache_key): + def inner_fn(fn): + @wraps(fn) + def wrapper(self, *args, **kwargs): + instance = getattr(self, cache_key) + if instance is not None: + return instance + + instance = fn(self, *args, **kwargs) + setattr(self, cache_key, instance) + return instance + + return wrapper + + return inner_fn |