Why are variables defined with 'self' automatically given a ListWrapper() while inheriting from tf.keras.Model?

我的未来我决定 提交于 2020-12-26 04:04:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!