Last active
November 10, 2019 11:47
-
-
Save Ending2015a/e53d5c7e92d6dc95fcb30f9bc9c6e51e to your computer and use it in GitHub Desktop.
The minimal code that would cause an unexpected KeyError in TF2.0
This file contains 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 tensorflow as tf #tf2.0 | |
from collections import OrderedDict | |
class MyNamedTuple(OrderedDict): | |
def __iter__(self): # iterate over values to unpack, e.g., arg1, arg2, arg3 = MyNamedTuple(...) | |
for v in self.values(): | |
yield v | |
class MyModule(tf.Module): | |
def __call__(self): | |
self.module = MyNamedTuple({'arg': 'hello'}) # cause KeyError | |
self.v = tf.Variable([1, 2, 3]) # some variables | |
module = MyModule('my_module') | |
module() | |
print(module.variables) #KeyError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment