Skip to content

Commit

Permalink
Fix Torch.Models.Model.BasicModel can't init twice
Browse files Browse the repository at this point in the history
  • Loading branch information
LoSealL committed Jul 29, 2020
1 parent ad66a63 commit d366528
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1.0.6
1.0.6.1

## 1.0.6
## 2020-07
Expand Down
16 changes: 10 additions & 6 deletions VSR/Backend/Torch/Models/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class BasicModel(object):
- opts: contains a K-V pair of `str: optim.Optimizer`. Will be automatically
appended if a derived object assign any attribute with `optim.Optimizer`.
"""
modules = OrderedDict()
opts = OrderedDict()
name = ''
loaded = None
_trainer = None

def _setup(self):
self.setup = True
self.modules = OrderedDict()
self.opts = OrderedDict()
self.name = ''
self.loaded = None

def __setattr__(self, key, value):
if key in ('modules', 'opts',):
if not hasattr(self, 'setup') and key != 'setup':
self._setup()
if key in ('modules', 'opts', 'setup'):
if hasattr(self, key):
raise ValueError(f"Can't overwrite built-in '{key}' of BasicModel")
if isinstance(value, torch.nn.Module):
Expand Down

0 comments on commit d366528

Please sign in to comment.