Skip to content

Instantly share code, notes, and snippets.

@Swalloow
Created April 22, 2018 09:11
Show Gist options
  • Save Swalloow/e736f8a33f72184cec349146c58b7998 to your computer and use it in GitHub Desktop.
Save Swalloow/e736f8a33f72184cec349146c58b7998 to your computer and use it in GitHub Desktop.
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