mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-10 12:21:57 +08:00
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:
committed by
William Falcon
parent
32e74b8f36
commit
36f0b5bbd0
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user