Last active
September 10, 2015 21:52
-
-
Save rizar/ef605c0d23acec7f17d2 to your computer and use it in GitHub Desktop.
Strip computation graph off annotations
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
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