问题
I am not familiar with ListWrapper()
, but it is being applied to all list variables created with self
when my class inherits from tf.keras.Model
.
https://www.tensorflow.org/api_docs/python/tf/keras/models/Model
This is bad because it is causing an IndexError
when I use it in certain functions, or even by just passing it through my Tensorflow model. (I am using eager execution)
A small reproduction of the problem can be seen with this code:
import tensorflow as tf
class my_class(tf.keras.Model):
def __init__(self):
super(my_class, self).__init__()
self.x = [0]
print(self.x)
model = my_class()
Output:
ListWrapper([0])
Switching the inheritance to be from object
solves the issue, which is how I know its tf.keras.Model
that is causing this.
I tried looking it up but can't find anything on this. Any tips? Thanks!
回答1:
Turns out this was a bug in Tensorflow between tf.keras.Model and eager execution. This was not "how the tensorflow has 'patched' setting attributes", as suggested by a comment.
This is a link to the closed issue on Tensorflow: https://github.com/tensorflow/tensorflow/issues/22853
If you have this problem, it should be fixed in the next Tensorflow update. This bug was in version 1.11.0
来源:https://stackoverflow.com/questions/52671481/why-are-variables-defined-with-self-automatically-given-a-listwrapper-while