Skip to content

Instantly share code, notes, and snippets.

@rizar
Last active September 10, 2015 21:52
Show Gist options
  • Save rizar/ef605c0d23acec7f17d2 to your computer and use it in GitHub Desktop.
Save rizar/ef605c0d23acec7f17d2 to your computer and use it in GitHub Desktop.
Strip computation graph off annotations
seen = set()
def strip(obj):
if id(obj) in seen:
return
seen.add(id(obj))
if isinstance(obj, theano.Variable):
obj.tag.annotations = []
obj.tag.roles = []
if isinstance(obj, (list, tuple, set)):
for el in obj:
strip(el)
if isinstance(obj, dict):
for key, value in obj.items():
strip(key)
strip(value)
if hasattr(obj, '__dict__'):
for attr, value in obj.__dict__.items():
if not attr.startswith('_'):
strip(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment