Use getter instead of python property for the dataloaders (#275)

* Use getter instead of python property for the dataloaders

* Fix lint

* Update trainer.py
This commit is contained in:
Hendrik Schröter
2019-10-04 15:35:02 -04:00
committed by William Falcon
parent 32e74b8f36
commit 36f0b5bbd0
3 changed files with 57 additions and 53 deletions
+8 -3
View File
@@ -10,13 +10,18 @@ def data_loader(fn):
attr_name = '_lazy_' + fn.__name__
@property
def _data_loader(self):
def _get_data_loader(self):
try:
value = getattr(self, attr_name)
except AttributeError:
try:
value = fn(self) # Lazy evaluation, done only once.
if (
value is not None and
not isinstance(value, list) and
fn.__name__ in['test_dataloader', 'val_dataloader']
):
value = [value]
except AttributeError as e:
# Guard against AttributeError suppression. (Issue #142)
traceback.print_exc()
@@ -25,4 +30,4 @@ def data_loader(fn):
setattr(self, attr_name, value) # Memoize evaluation.
return value
return _data_loader
return _get_data_loader