Created
April 22, 2018 09:11
-
-
Save Swalloow/e736f8a33f72184cec349146c58b7998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def define_scope(function): | |
attribute = '_cache_' + function.__name__ | |
@property | |
@functools.wraps(function) | |
def decorator(self): | |
if not hasattr(self, attribute): | |
with tf.variable_scope(function.__name): | |
setattr(self, attribute, function(self)) | |
return getattr(self, attribute) | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment